Syntax missing operator error

AndyCompanyZ

Registered User.
Local time
Today, 04:14
Joined
Mar 24, 2011
Messages
223
I have a syntax error on the following code:
Code:
If Me!SubTeamHeadDelID = Me!DelegateID Then
Dim strID As String
Dim strID2 As String
 Debug.Print SubTeamParentID
 Debug.Print SubTeam
 strID = DLookup("SubTeamParentID", "tblSubTeam", "SubTeam = " & Me!SubTeam)
 
 If strID = Null Then
 MsgBox "You don't need to contact anyone or whatever is needed"
 Else
 strID2 = DLookup("DelegateMobileNumber", "tblDelegate", "ID =" & strID)
 MsgBox "Please contact this SubTeamLeader  & strID2", vbOKOnly
 End If
 End If
It runs through the first debugs and gives results in the immediate window that are correct but when it comes to the
strID = DLookup("SubTeamParentID", "tblSubTeam", "SubTeam = " & Me!SubTeam)
line it says there is a syntax error missing operator in it. Can anyone see the syntax error please.
 
I have changed the code so it now reads :
Code:
If Me!SubTeamHeadDelID = Me!DelegateID Then
Dim strID As String
Dim strID2 As String
Dim strID3 As String
 Debug.Print SubTeamParentID
 Debug.Print SubTeam
 strID = DLookup("[SubTeamParentID]", "[tblSubTeam]", "[SubTeam] =" & Me![SubTeam])
 
 If strID = Null Then
 MsgBox "You don't need to contact anyone or whatever is needed"
 Else
 strID2 = DLookup("ID", "tblSubTeam", "SubTeamParentID =" & strID)
strID3 = DLookup("DelegateMobileNumber", "tblDelegate", "ID =" & strID2)
 MsgBox "Please contact this SubTeamLeader  & strID3", vbOKOnly
 End If
 End If
It still gives me the same error but it should be correct in what i want it to do.
 
Is SubTeam a numeric field or text field? If text you need quotes.
 
I changed the offending line to:
strID = DLookup("[SubTeamParentID]", "[tblSubTeam]", "[SubTeam]=" & Me![SubTeam] & "''") but still giving me a syntax error. Not sure about the amount of "'" s needed is it " ' ' " or "'"
 
For strings:

"[SubTeam]='" & Me![SubTeam] & "'")

If SubTeam can have an apostrof in it like O'Neil then double up the quotes or use Chr(34) as delimiters.

"[SubTeam]=""" & Me![SubTeam] & """")

"[SubTeam]=" & Chr(34) & Me![SubTeam] & Chr(34))

JR
 

Users who are viewing this thread

Back
Top Bottom