T
tguenther
Hi,
I'm not familiar with VBScript and need some help with the Item_Send
event in the code behind a custom mail message form.
I want to cycle through an access table and send an email to each
contact in the record. I have created the code I want to execute in an
Access database but of course not sending the email. Here is my code:
I need to write it in VBScript
Dim DB As DAO.database
Dim RS As DAO.Recordset
Dim SQ As String
Dim lcDatbase As String
Set DB = DAO.OpenDatabase("C:\Documents and Settings\t\My
Documents\eml") ' or whatever database you want using the path to it
SQ = "Select * from eml"
Set RS = DB.OpenRecordset(SQ, dbOpenDynaset)
While Not RS.EOF
Dim lcConEmail As String
Dim lcName As String
If Not IsNull(RS!) Then
lcConEmail = RS![email]
Else
lcConEmail = ""
End If
If Not IsNull(RS![contact]) Then
lcName = RS![contact]
Else
lcName = ""
End If
'Don't send message if no email address
If lcConEmail <> "" And lcName <> "" Then
Set mOApp = New Outlook.Application
Set mONs = mOApp.GetNamespace("MAPI")
Set mOMailItem = mOApp.CreateItemFromTemplate("c:\Documents and
Settings\t\My Documents\test.oft")
With mOMailItem
.To = lcConEmail
lcName = Replace(lcName, Chr(34), "")
lcBody = "Dear {Recipient}"
NewBody = Replace(lcBody, "{Recipient}", lcName)
.Body = NewBody
If .Recipients.ResolveAll Then
.Send
End If
End With
Else
lnOk = MsgBox("No contact or email to create mail message",
vbOKOnly, "Message")
End If
RS.MoveNext
Wend
I'm not familiar with VBScript and need some help with the Item_Send
event in the code behind a custom mail message form.
I want to cycle through an access table and send an email to each
contact in the record. I have created the code I want to execute in an
Access database but of course not sending the email. Here is my code:
I need to write it in VBScript
Dim DB As DAO.database
Dim RS As DAO.Recordset
Dim SQ As String
Dim lcDatbase As String
Set DB = DAO.OpenDatabase("C:\Documents and Settings\t\My
Documents\eml") ' or whatever database you want using the path to it
SQ = "Select * from eml"
Set RS = DB.OpenRecordset(SQ, dbOpenDynaset)
While Not RS.EOF
Dim lcConEmail As String
Dim lcName As String
If Not IsNull(RS!) Then
lcConEmail = RS![email]
Else
lcConEmail = ""
End If
If Not IsNull(RS![contact]) Then
lcName = RS![contact]
Else
lcName = ""
End If
'Don't send message if no email address
If lcConEmail <> "" And lcName <> "" Then
Set mOApp = New Outlook.Application
Set mONs = mOApp.GetNamespace("MAPI")
Set mOMailItem = mOApp.CreateItemFromTemplate("c:\Documents and
Settings\t\My Documents\test.oft")
With mOMailItem
.To = lcConEmail
lcName = Replace(lcName, Chr(34), "")
lcBody = "Dear {Recipient}"
NewBody = Replace(lcBody, "{Recipient}", lcName)
.Body = NewBody
If .Recipients.ResolveAll Then
.Send
End If
End With
Else
lnOk = MsgBox("No contact or email to create mail message",
vbOKOnly, "Message")
End If
RS.MoveNext
Wend