home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 2000 March / pcp161b.iso / handson / archive / Issue159 / files / vbwkshp / main.bas < prev    next >
Encoding:
BASIC Source File  |  1999-10-20  |  1.3 KB  |  66 lines

  1. Attribute VB_Name = "Code"
  2. Option Explicit
  3. Dim ol As Outlook.Application
  4. Dim ns As Outlook.NameSpace
  5. Dim MsgText As String
  6. Public issueNumber As Integer
  7.  
  8. Public Sub Main()
  9. Set ol = New Outlook.Application
  10. Set ns = ol.GetNamespace("MAPI")
  11. issueNumber = 159
  12.  
  13. ns.Logon "", , True, True
  14. Call ReadFile
  15. MainForm.Show
  16.  
  17. End Sub
  18. Public Sub SendAllMail()
  19.  
  20. MainForm.Data1.Refresh
  21. With MainForm.Data1.Recordset
  22.     While Not .EOF
  23.         SendMail .Fields!Name, .Fields!EMail
  24.         .MoveNext
  25.     Wend
  26. End With
  27.  
  28. End Sub
  29. Public Sub SendMail(n As String, dest As String)
  30. Dim newMail As Outlook.MailItem
  31.  
  32.  
  33. Set newMail = ol.CreateItem(olMailItem)
  34. With newMail
  35.     .Subject = "PC Plus Knitting Circle News (September)"
  36.     .Body = MsgText
  37.     With .Recipients.Add(dest)
  38.          .Type = olTo
  39.     End With
  40.     With .Attachments.Add _
  41.         (App.Path & "\attachment.rtf", olByValue, 1, "The Winter Warmer")
  42.     End With
  43.     .Send
  44. End With
  45.  
  46.     With MainForm.Data2.Recordset
  47.         .AddNew
  48.         !Name = n
  49.         !DateSent = Now
  50.         !issueNumber = issueNumber
  51.         .Update
  52.     End With
  53. Set newMail = Nothing
  54.  
  55. End Sub
  56. Private Sub ReadFile()
  57. Dim NextLine As String
  58.  
  59. Open App.Path & "\news.txt" For Input As #1
  60. Do Until EOF(1)
  61.     Line Input #1, NextLine
  62.     MsgText = MsgText + NextLine + vbCrLf
  63. Loop
  64.  
  65. End Sub
  66.