Filter Help

R

Richard

I use the below code to filter my form. This filter matches any where in the
phone string. What I am looking for is the exact match. Thanks for any help.

Private Sub cmdPhoneNumber_Click()
' Find the record that matches the control.
Dim stFilter As String

Me.FilterOn = False

stFilter = "[Phone] Like '*" & Me.[txtPhoneNumber] & "*'"


Me.Filter = stFilter
Me.FilterOn = True

End Sub
 
R

Richard

I changed the code to your suggestion but I now get a run-time error '2448'
"You can't assign a value to this object". Also the code breaks on the
following line:

Me.Filter = stFilter

Richard


Mr. B said:
You need to remove the Like and "*" from the equation

stFilter = "[Phone] = " & Me.[txtPhoneNumber] & "'"

-----
HTH
Mr. B
http://www.askdoctoraccess.com/
Doctor Access Downloads Page:
http://www.askdoctoraccess.com/DownloadPage.htm


Richard said:
I use the below code to filter my form. This filter matches any where in the
phone string. What I am looking for is the exact match. Thanks for any help.

Private Sub cmdPhoneNumber_Click()
' Find the record that matches the control.
Dim stFilter As String

Me.FilterOn = False

stFilter = "[Phone] Like '*" & Me.[txtPhoneNumber] & "*'"


Me.Filter = stFilter
Me.FilterOn = True

End Sub
 
D

Duane Hookom

It looks like there is a missing single quote after Phone =. Try:

stFilter = "[Phone] = '" & Me.[txtPhoneNumber] & "'"

--
Duane Hookom
MS Access MVP

Richard said:
I changed the code to your suggestion but I now get a run-time error
'2448'
"You can't assign a value to this object". Also the code breaks on the
following line:

Me.Filter = stFilter

Richard


Mr. B said:
You need to remove the Like and "*" from the equation

stFilter = "[Phone] = " & Me.[txtPhoneNumber] & "'"

-----
HTH
Mr. B
http://www.askdoctoraccess.com/
Doctor Access Downloads Page:
http://www.askdoctoraccess.com/DownloadPage.htm


Richard said:
I use the below code to filter my form. This filter matches any where
in the
phone string. What I am looking for is the exact match. Thanks for any
help.

Private Sub cmdPhoneNumber_Click()
' Find the record that matches the control.
Dim stFilter As String

Me.FilterOn = False

stFilter = "[Phone] Like '*" & Me.[txtPhoneNumber] & "*'"


Me.Filter = stFilter
Me.FilterOn = True

End Sub
 
J

John W. Vinson

I changed the code to your suggestion but I now get a run-time error '2448'
"You can't assign a value to this object". Also the code breaks on the
following line:

Me.Filter = stFilter

Richard


Mr. B said:
You need to remove the Like and "*" from the equation

stFilter = "[Phone] = " & Me.[txtPhoneNumber] & "'"

Possibly Mr. B had a tiny typo, which might be causing this problem: there's a
missing quotemark. Try

stFilter = "[Phone] = '" & Me.[txtPhoneNumber] & "'"

This will evaluate to

[Phone] = '(222) 222-2222'

which should work correctly as a filter string.

I'm thinking this may be the case because your original LIKE filter string was
(sort of) working....
 
R

Richard

Yes that did work thanks to all

Richard

John W. Vinson said:
I changed the code to your suggestion but I now get a run-time error '2448'
"You can't assign a value to this object". Also the code breaks on the
following line:

Me.Filter = stFilter

Richard


Mr. B said:
You need to remove the Like and "*" from the equation

stFilter = "[Phone] = " & Me.[txtPhoneNumber] & "'"

Possibly Mr. B had a tiny typo, which might be causing this problem: there's a
missing quotemark. Try

stFilter = "[Phone] = '" & Me.[txtPhoneNumber] & "'"

This will evaluate to

[Phone] = '(222) 222-2222'

which should work correctly as a filter string.

I'm thinking this may be the case because your original LIKE filter string was
(sort of) working....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top