Share via

I need help with this problem: syntax error, missing operator in query expression

Anonymous
2016-07-19T15:28:25+00:00

I keep getting this syntax error, missing operator in query expression  [ID] = Soldering System. Can someone please help me?

Dim oOutlook As Outlook.Application

Dim oEmailAddress As MailItem

Dim MyEmpName As String

Dim temp As String

Dim MyEquip As String

Dim MyModel As String

Dim MyAsset As String

Dim MySerial As String

Dim rs As Recordset

Set rs = CurrentDb.OpenRecordset(MySQL)

If rs.RecordCount > 0 Then

    rs.MoveFirst

    Do Until rs.EOF

    If IsNull(rs!EmailAddress) Then

            rs.MoveNext

Else

    If oOutlook Is Nothing Then

    Set oOutlook = New Outlook.Application

  End If

  Set oEmailAddressItem = oOutlook.CreateItem(olMailItem)

  With oEmailAddressItem

               MyEmpName = DLookup("EmpName", "Employees", "[EmpID]= " & rs!EmpName)

                MyEquip = DLookup("[EquipmentType]", "Equipment", "[ID]=" & rs!EquipmentType)   This is the line where I keep getting that error message as well as the three Dlookup statements below.

                MyModel = DLookup("ModelNo", "Equipment", "[ID]= " & rs!ModelNo)

                MyAsset = DLookup("AssetNo", "Equipment", "[ID]= " & rs!AssetNo)

                MySerial = DLookup("SerialNo", "Equipment", "[ID]= " & rs!SerialNo)

                .To = "another@.com;another@.com;another@.com"

                .Subject = "Calibration that's due between 1 to 11 months" & MyEmpName

                .Body = "Calibration ID: " & rs!RecordID & vbCr & _

                        "Location: " & rs!CalLocation & vbCr & _

                       "Requirement: " & rs!Requirement & vbCr & _

                       "Employee: " & MyEmpName & vbCr & _

                       "Name: " & MyEquip & vbCr & _

                       "Serial No.: " & MySerial & vbCr & _

                       "Model No.: " & MyModel & vbCr & _

                       "Asset No.: " & MyAsset & vbCr & _

                       "Due Date : " & rs!CalUpcomingDate & vbCr & vbCr & _

                       "This email is auto generated. Please Do Not Replay!"

                 .Display

                 '.Send

                 ' rs.Edit

                 ' rs!DateEmailSent = Date

                 ' rs.Update

          End With

          Set oEmailAddressItem = Nothing

          Set oOutlook = Nothing

          rs.MoveNext

      End If

    Loop

Else

'do nothing

End If

rs.Close

Exit_Function:

    Exit Function

End Function

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

9 answers

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  2. HansV 462.6K Reputation points
    2016-07-19T18:52:16+00:00

    If you want the user to be able to select recipients, you should create a form with - for example - a multi-select list box that lists the e-mail addresses. The user can select one or more of them, and you can use this in your code to populate the To property of the mail item.

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2016-07-19T18:24:13+00:00

    Thank you I will take a look at the links. I forgot to ask the first time I post the question. In the post above I want to know how do you include everybody that has an email in one email without putting everybody email in manually. Also is there a possible way to create a list for specific people to receive specific emails even though everybody has an email. Can you create a pop up list of emails to choose who can receive specific email.

    This is the example from the post earlier 

    .To = "another@.com;another@.com;another@.com"

    Was this answer helpful?

    0 comments No comments
  4. HansV 462.6K Reputation points
    2016-07-19T17:17:07+00:00

    The following are for an older version of Office but they should still work (but you'd have to set a reference to your version of Outlook obviously).

    For a task: https://support.microsoft.com/en-us/kb/162371

    For an appointment: https://support.microsoft.com/en-us/kb/160502

    Was this answer helpful?

    0 comments No comments