vb search code

  • Thread starter Thread starter ghost
  • Start date Start date
G

ghost

Greeting,
I put the following code in command button and it gives me an error"Type
mismatch"

this code for search as part of name:
Me.RecordSource = "SELECT t1.* FROM t1 WHERE (((t1.[Employeename]) Like
forms!f1!m & " * "));"

Any help please?
 
Greeting,
I put the following code in command button and it gives me an error"Type
mismatch"

Since you're searching a text field you need the syntactically required ' or "
delimiters. Given that names might contain apostrophes (D'Angelo for example,
or O'Brien) it's better to use doublequotes; to insert a doublequote in a
doublequote delimited string double the doublequote:

Me.RecordSource = "SELECT t1.* FROM t1 WHERE (((t1.[Employeename]) Like """ &
forms!f1!m & """*"));"

This string will evaluate to something like

SELECT t1.* FROM t1 WHERE (((t1.[Employeename]) Like "Smith*"))

Note that your table should probably (if it doesn't already) have separate
FirstName and Surname fields rather than putting the full name into a single
field.
 
Back
Top