filter with a variable

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I trying to search by last name, [last], in a form using a command button, but want search to pull up matching names even if they have Jr. or Sr. etc... afterwards, so want to use [last] with an asterisk.

have tried

lastname = Me![Last] & "*

Me.Filter = "last = " & lastnam
Me.FilterOn = Tru

Seems simple, but this and other variations don't work. how should the criteria be written in the filter statement
thanks!!!
 
Your form have recordsource: table or query

Sub ButtonFind_Click(

Dim sFindRecords as Strin

sFindRecords = "SELECT * FROM TableName WHERE ((TbaleName.LastName) Like " & Me.Last & "*);

Me.Recordsource = sFindRecord

End Su

Sub ButtonRestore_Click(

Dim sAllRecords as Strin
sAllRecords = "SELECT * FROM TableName;

Me.Recordsource = sAllRecord

End Sub
 
lastname = Me!Last & "*"
Me.Filter = "[last] Like'" & lastname & "'"
Me.FilterOn = True
-----Original Message-----
I trying to search by last name, [last], in a form using
a command button, but want search to pull up matching
names even if they have Jr. or Sr. etc... afterwards, so
want to use [last] with an asterisk.
have tried:

lastname = Me![Last] & "*"

Me.Filter = "last = " & lastname
Me.FilterOn = True

Seems simple, but this and other variations don't work.
how should the criteria be written in the filter statement?
 
When using single quotes, look out for last names that
have an apostrophe in them, like O'Connor. You will get
an error. You might try changing the example below as
follows, to eliminate use of single quotes and to use the
ascii character code for double quotes:

Me.Filter = "[last] Like " & Chr(34) & lastname & Chr(34)

-----Original Message-----
thank you!!

----- Elwin wrote: -----

lastname = Me!Last & "*"
Me.Filter = "[last] Like'" & lastname & "'"
Me.FilterOn = True
-----Original Message-----
I trying to search by last name, [last], in a form
using
a command button, but want search to pull up matching
names even if they have Jr. or Sr. etc... afterwards, so
want to use [last] with an asterisk.
have tried:
lastname = Me![Last] & "*"
Me.Filter = "last = " & lastname Me.FilterOn = True
Seems simple, but this and other variations don't
work.
how should the criteria be written in the filter statement?
thanks!!!
.
.
 
Back
Top