akins4lyfe
Programmer
i have a listbox control placed on a form, "frmEmail". Users can select email address and click on a button to send email to a selected contact. I keep getting the above error, on these lines
.To = strEmailRecipient
.Subject = StrSubject
.Body = StrBody
.Display
kindly assist.
thanks.
Codes
Private Sub Form_Load()
Me.lstMembers.ColumnHeads = True
Me.lstMembers.ColumnCount = 3
Me.lstMembers.RowSourceType = "Table/Query"
Me.txtMessagebdy = "There will be a meeting on this friday at 2PM in the boardroom."
Me.txtSubject = "Meeting Reminder"
Call Populate
End Sub
Private Sub Populate()
Dim strSQL As String
strSQL = "SELECT tblMember.[First Name], tblMember.[Last Name], tblMember.EmailAddress "
strSQL = strSQL & " FROM tblMember;"
Me.lstMembers.RowSource = strSQL
End Sub
Private Sub Command4_Click()
'check that at least one member have been selected
If lstMembers.ItemsSelected.Count = 0 Then
MsgBox "Please Select at least one member", vbOKOnly, "Required Field"
lstMembers.SetFocus
End If
'test for required fields
If IsNull(Me.txtSubject) Then
MsgBox "Please enter a subject", vbOKOnly, "Required Field"
Me.txtSubject.SetFocus
End If
If IsNull(Me.txtMessagebdy) Then
MsgBox "Please enter a message", vbOKOnly, "Required Field"
Me.txtMessagebdy.SetFocus
End If
'check for email addresses
Dim strEmailRecipient As String
Dim VarItem As Variant
Dim appOutlook As Outlook.Application
Dim StrSubject As String
Dim StrBody As String
Dim msg As DAO.Recordset
strEmailRecipient = Nz(lstMembers.Column(2, VarItem))
Debug.Print "Email address: & "; strEmailRecipient
If strEmailRecipient = "" Then
End If
'create new mail message and send to current contact
Set appOutlook = GetObject(, "Outlook.Application")
Set msg = appOutlook.CreatItem(olMailItem)
With msg
.To = strEmailRecipient
.Subject = StrSubject
.Body = StrBody
.Display
End With
End Sub