Solved Missing Operator error in VBA Query (1 Viewer)

bconner

Registered User.
Local time
Yesterday, 20:38
Joined
Dec 22, 2008
Messages
183
Below is the query I have built and it runs fine if I just filter Where MCID= txtMCID but fails when I add the OR Member_Id = txtMemberId.
txtMCID is a integer and txtMemberId is a string.

Code:
strSQLMember = "SELECT * FROM dbo_vw_RAA_Member_Information WHERE [MCID]=" & txtMCID & " or [Member_Id]='" & txtMemberId & "'"""
Set rs = db.OpenRecordset(strSQLMember, dbOpenDynaset, dbSeeChanges)

Any help is greatly appreciated.
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 18:38
Joined
Oct 29, 2018
Messages
21,489
Looks like maybe you have two extra quotes at the end there.
 

bconner

Registered User.
Local time
Yesterday, 20:38
Joined
Dec 22, 2008
Messages
183
I tried the below but still get the same error.
The way the form is set up the user can enter either a MCID or Member_Id which means one field or the other can be null, does that matter?

Code:
strSQLMember = "SELECT * FROM dbo_vw_RAA_Member_Information WHERE [MCID]=" & txtMCID & " or [Member_Id]= '" & txtMemberId & "'"
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 18:38
Joined
Oct 29, 2018
Messages
21,489
I tried the below but still get the same error.
The way the form is set up the user can enter either a MCID or Member_Id which means one field or the other can be null, does that matter?

Code:
strSQLMember = "SELECT * FROM dbo_vw_RAA_Member_Information WHERE [MCID]=" & txtMCID & " or [Member_Id]= '" & txtMemberId & "'"
Do a Debug.Print strSQLMember and copy and paste the result from the Immediate Window into the Query Designer to get an idea of what is wrong with it.
 

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 21:38
Joined
Feb 19, 2002
Messages
43,331
It is more efficient to qualify form/report control names with Me. Plus, doing so gives you intellisense.

strSQLMember = "SELECT * FROM dbo_vw_RAA_Member_Information WHERE [MCID]=" & Me.txtMCID & " or [Member_Id]= '" & Me.txtMemberId & "'"
 

bconner

Registered User.
Local time
Yesterday, 20:38
Joined
Dec 22, 2008
Messages
183
theDBguy, thank you for pointing me in the right direction I appreciate your help.

I edited the code to the below and it worked.

Code:
InttxtMCID = Nz(txtMCID, 0)
strtxtMemberId = Nz(txtMemberId, Null)

Set db = CurrentDb
'Fetch and populate the Member information on the form
strSQLMember = "SELECT * FROM dbo_vw_RAA_Member_Information WHERE [MCID]= " & InttxtMCID & " or [Member_Id]= '" & strtxtMemberId & "'"
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 18:38
Joined
Oct 29, 2018
Messages
21,489
theDBguy, thank you for pointing me in the right direction I appreciate your help.

I edited the code to the below and it worked.

Code:
InttxtMCID = Nz(txtMCID, 0)
strtxtMemberId = Nz(txtMemberId, Null)

Set db = CurrentDb
'Fetch and populate the Member information on the form
strSQLMember = "SELECT * FROM dbo_vw_RAA_Member_Information WHERE [MCID]= " & InttxtMCID & " or [Member_Id]= '" & strtxtMemberId & "'"
Hi. Congratulations! Glad to hear you got it sorted out. Good luck with your project.
 

Users who are viewing this thread

Top Bottom