By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,997 Members | 1,260 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,997 IT Pros & Developers. It's quick & easy.

Apply filter on number field

P: 13
Can anybody out there help me please on apply filter in MS Access. I have a form that create from the query, which contain field chidid (text field), in the form footer, I add the button to open another form (searchF form), which have an unbound text box (text1). It works fine with this code:

DoCmd.ApplyFilter , "childid='" & Form_SearchF.Text1 & "'"

But if I change the data type of childid field to number it does't work. The error message is :

" Run-time error 2501
The Applyfilter action was canceled"

Your responds are highly appreciated.

Thanks.
Aug 22 '07 #1
Share this Question
Share on Google+
2 Replies


puppydogbuddy
Expert 100+
P: 1,923
Can anybody out there help me please on apply filter in MS Access. I have a form that create from the query, which contain field chidid (text field), in the form footer, I add the button to open another form (searchF form), which have an unbound text box (text1). It works fine with this code:

DoCmd.ApplyFilter , "childid='" & Form_SearchF.Text1 & "'"

But if I change the data type of childid field to number it does't work. The error message is :

" Run-time error 2501
The Applyfilter action was canceled"

Your responds are highly appreciated.

Thanks.
The syntax you are using above is for text data types. For a numeric data type the syntax would be as follows (remove the extra spaces inserted by the text editor):

DoCmd.ApplyFilter "childid=" & Form_SearchF.Text1

If you need to deal with both data types, you could do it like this:
Expand|Select|Wrap|Line Numbers
  1. If IsNumeric(Me!childid) then
  2.     DoCmd.ApplyFilter  "childid="  & Form_SearchF.Text1
  3. Else
  4.     DoCmd.ApplyFilter "childid='" & Form_SearchF.Text1 & "'"
  5. End If
Aug 22 '07 #2

P: 13
The syntax you are using above is for text data types. For a numeric data type the syntax would be as follows (remove the extra spaces inserted by the text editor):

DoCmd.ApplyFilter "childid=" & Form_SearchF.Text1

If you need to deal with both data types, you could do it like this:
Expand|Select|Wrap|Line Numbers
  1. If IsNumeric(Me!childid) then
  2.     DoCmd.ApplyFilter  "childid="  & Form_SearchF.Text1
  3. Else
  4.     DoCmd.ApplyFilter "childid='" & Form_SearchF.Text1 & "'"
  5. End If


Thank you very much puppydogbuddy. It works well right now.
I appreciated your quick respond.
Aug 22 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.