stLinkCriteria and OR

hockeyfan21

Registered User.
Local time
Today, 04:02
Joined
Aug 31, 2011
Messages
38
Hi,

I'm having trouble with the below code - When I initially open the database and select an item in cboASR, I get this error message:
Syntax error (missing operator) in query expression 'ASR User Id] = 'thart' OR'

If I then select something in cboCust as well, it works fine, then I can go back and select an item in cboASR.
What can I do to avoid the error on the initial selection?

If Not IsNull(Me.cboASR) Then
stLinkCriteria = "[ASR User Id]= '" & Me.cboASR & "' OR"
End If
If Not IsNull(Me.cboCust) Then
stLinkCriteria = stLinkCriteria & "[Sold To Name]='" & Me.cboCust & "' "
End If

DoCmd.OpenForm stDocName, , , stLinkCriteria

Thanks in advance for any help with this!
Toni
 
If the user will always choose the first, move the OR to the second, like:

stLinkCriteria = stLinkCriteria & " OR [Sold To Name]='" & Me.cboCust & "' "
 
What is the *OR* for? What happens if you change it to...

Code:
If Not IsNull(Me.cboASR) Then
   stLinkCriteria = "[ASR User Id]= '" & Me.cboASR & "'"
End If
 
@pbaldy

Yes, I know that but wondering why it ia there as it will produce an error if nothing is on the other side (well at least the way the OP has done it. Your way will not because it is not at the end of the first line. Okay, I guess I could have been clearer. :o
 
Pure genius!!! Thank you so much, that worked perfectly, was driving me crazy!
 
Whoever's solution you used was glad to provide it. ;)
 

Users who are viewing this thread

Back
Top Bottom