I've been working on this vba code to extract email addresses via sql select statement. Using where variables from the search form.


Everything seems right. But when I run the code, I recieve the same syntax error(missing operator). I'm thinking of a data mismatch error. But That may not be the case.


I'm all out of clues. Can anyone help me out?


Here's my code:

Private Sub Command14_Click()


Dim MyDb As Database
Dim MyRS As Recordset
Dim strSQL As String
Dim Address As String


strSQL = "SELECT * FROM " & "qryAttendance " _
& "WHERE (type of conference='" & Forms!frmAttendanceSearchView![Type of Conference] & "' and times attended >= " & CLng(Forms!frmAttendanceSearchView![Times Attended]) & ");"

Set MyDb = CurrentDb
Set MyRS = MyDb.OpenRecordset(strSQL)
MyRS.MoveFirst

Set objOutlook = CreateObject("outlook.application")

Do Until MyRS.EOF
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
Address = MyRS![Email]

With objOutlookMsg
Set objOutlookRecip = .Recipients.add(TheAddress)
objOutlookRecip.Type = olTo

.Subject = "test"
.Body = "test body"
.Importance = olImportanceHigh

For Each obbjOutlookRecip In .Recipients
objOutlookRecip.Resolve
If Not objOutlookRecip.Resolve Then
objOutlookMsg.Display
End If
Next
.Send
End With
MyRS.MoveNext
Loop
Set objOutlookMsg = Nothing
Set objOutlook = Nothing
End Sub