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. Anonymous
    2016-07-19T16:42:45+00:00

    How do you create a automatic 3 month email reminder or yearly reminder from access to outlook?

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2016-07-19T16:40:09+00:00

    I tried to do it that way, but it did not work for me at all. Thank you for your help.

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2016-07-19T15:56:35+00:00

    Thank you so much=)

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2016-07-19T15:50:50+00:00

    Hi,

    try to change into:

          MyEquip = DLookup("[EquipmentType]", "Equipment", "[ID]='" & rs!EquipmentType &"'")

    Ciao Mimmo

    Was this answer helpful?

    0 comments No comments
  5. HansV 462.6K Reputation points
    2016-07-19T15:33:03+00:00

    It looks like rs!EquipmentType is a text field that contains the name of the equipment type, not its ID. So you may be able to use

            MyEquip = rs!EquipmentType

    Was this answer helpful?

    0 comments No comments