Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open form using wildcard 1

Status
Not open for further replies.

kieranplatt1

Programmer
Jan 21, 2004
17
GB
Hi, hope someone can help. I am trying to open a form to display certain records i.e. users type in a surname or part of a surname into a field 'goto' - I want the form to display all records where either 'surname1' OR 'surname2' (these are Mr & Mrs records which could have couples with differing surnames) begin with the letters input into 'goto'. I am trying to use wildcard - this is the code I have tried...

Private Sub Command111_Click()
On Error GoTo MyError
DoCmd.OpenForm "ClientsTab", , , "[Surname1] = '" & Me![goto] & "*'" or [Surname2] = '" & Me![goto] & "*'"
Exit Sub
MyError:
MsgBox (Err.Number & "-" & Err.Description)
End Sub

any offers!? Thanks, Kieran.
 
Instead of using = , if you want to use wildcards, use the "Like" word instead:

DoCmd.OpenForm "ClientsTab", , , "[Surname1] Like '" & Me![goto] & "*'" or [Surname2] Like '" & Me![goto] & "*'"
 
Works fine for SURNAME1 but does not like the syntax for SURNAME2 - it is showing in red - can you use OR in this statement?

regards

Kieran
 
Sorry,

Didn't notice the extra quotes:

DoCmd.OpenForm "ClientsTab", , , "[Surname1] Like '" & Me![goto] & "*' or [Surname2] Like '" & Me![goto] & "*'"

John
 
Thank you for a speedy and successful post - have a star.

Kieran
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top