A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » New Users
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Filter Help



 
 
Thread Tools Display Modes
  #1  
Old March 16th, 2010, 11:35 PM posted to microsoft.public.access.gettingstarted
Richard
external usenet poster
 
Posts: 1,419
Default Filter Help

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
  #2  
Old March 17th, 2010, 12:11 AM posted to microsoft.public.access.gettingstarted
Mr. B[_4_]
external usenet poster
 
Posts: 171
Default Filter Help

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" wrote:

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

  #3  
Old March 17th, 2010, 03:39 AM posted to microsoft.public.access.gettingstarted
Richard
external usenet poster
 
Posts: 1,419
Default Filter Help

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" wrote:

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" wrote:

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

  #4  
Old March 17th, 2010, 03:52 AM posted to microsoft.public.access.gettingstarted
Duane Hookom[_4_]
external usenet poster
 
Posts: 316
Default Filter Help

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

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

--
Duane Hookom
MS Access MVP

"Richard" wrote in message
...
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" wrote:

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" wrote:

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


  #5  
Old March 17th, 2010, 04:05 AM posted to microsoft.public.access.gettingstarted
John W. Vinson
external usenet poster
 
Posts: 18,261
Default Filter Help

On Tue, 16 Mar 2010 20:39:01 -0700, Richard
wrote:

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" wrote:

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....
--

John W. Vinson [MVP]
  #6  
Old March 17th, 2010, 04:46 AM posted to microsoft.public.access.gettingstarted
Richard
external usenet poster
 
Posts: 1,419
Default Filter Help

Yes that did work thanks to all

Richard

"John W. Vinson" wrote:

On Tue, 16 Mar 2010 20:39:01 -0700, Richard
wrote:

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" wrote:

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....
--

John W. Vinson [MVP]
.

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 03:14 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.