Slight Problem With Syntax In VBA . .

Evagrius

Registered User.
Local time
Today, 15:08
Joined
Jul 10, 2010
Messages
170
Hi all,

Again I am blighted my eroneous syntax. Can anyone help please? I simply would like to use the "LIKE" operator to select only Assets that begin with XX.

I would also be grateful if someone could show me how to include an "AND"; this way I can have "LIKE" XX and LIKE AB"



Code:
Private Sub MyND_Click()
DoCmd.OpenReport "Fin Est", acViewReport, , "[Asset Number] Like XX" & "&*"""

End Sub
 
Code:
DoCmd.OpenReport "Fin Est", acViewReport, , "[Asset Number] Like 'XX*'"
 
Oops missed the second part (don't you want OR AB there?):

Code:
DoCmd.OpenReport "Fin Est", acViewReport, , "[Asset Number] Like 'XX*' OR [Asset Number] Like 'AB*'"

Or if you are wanting these anywhere in the Asset Number then you can use:
Code:
DoCmd.OpenReport "Fin Est", acViewReport, , "[Asset Number] Like '*XX*' And [Asset Number] Like '*AB*'"
 
Bob - you are a true gentleman sir and a descendant of ancient, royal and conquering warriors :)

Also, you are correct, I did mean OR and not AND since AND would have always returned 0 records. "OR" will be the one to return all records that begin with XX or AB.

Thank you Bob!!!
 

Users who are viewing this thread

Back
Top Bottom