Previous Thread

6/30/2006 8:32:19 AM    Search Box in form gives error
Hello, 
 
I am an Access beginner trying to create a form to search a database. 
 
Users enter the client's last name, and then a second form called 
 
"Contacts" will open with their information.  I got that working easily 
 
enough with the wizard, but I would like the users to be able to enter 
 
just the first part of a client's name, instead of having to match it 
 
exactly. 
 
This is what I have so far, based on other posts to this forum. 
 
stDocName = "Contacts" 
 
stLinkCriteria = "[LastName]=" & Me![SearchBox] & "*""" 
 
DoCmd.OpenForm stDocName, , , stLinkCriteria 
 
When I try and use the button this is attached to, I get the error 
 
"Syntax Error in String in Query expression '[LastName]=SMITH*""  Where 
 
SMITH is can be any name I enter in the Search Box. 
 
I have also tried the same code substituting "LIKE" instead of "=" 
 
after stLinkCriteria, but then I get a "Type mismatch" error.  Can 
 
someone tell me what I'm doing wrong? 
 
Thank you in advance for your assistance.



6/30/2006 11:18:59 AM    Re: Search Box in form gives error
Since your Last Name is a string, you need to have single quotes around 
 
it.  So it would be: 
 
stLinkCriteria = "[LastName] = '" & Me![SearchBox] & "'" 
 
or if you want to do the like statement 
 
stLinkCriteria = "[LastName] Like '" & Me![SearchBox] & "*'"