Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help with an error cause by filters

Status
Not open for further replies.

Eric6

Programmer
Jun 11, 2002
54
CA
Hello

i could really use help with an error i've been getting

i'm trying to use a filter to filter out information
in a form

the filter criteria is chosen from a drop down list
then the user clicks on a button, that button
opens a form and in the OnOpen Sub i have this code

Me.Filter = "RO = " & Number
Me.FilterOn = True

for some reason i get an error when i click on the button
to open the form

"You cancelled the previous operation"

if i comment out

Me.FilterOn = True

the error goes away but obviously my filter doesn't work...

i could really use help
thank you in advance
Eric
 
Try

DoCmd.ApplyFilter

You can supply a previously saved Query as Filter parameter or use a string defined Where clause.
HTH
Chris

 
no luck :(
i cant get it to work
i keep getting an error

when i try your code,
DoCmd.ApplyFilter ROFilter, "RO =" & Number

i get a "The ApplyFilter action was canceled" error
i looked and the "allowFilters" property is set to yes
i've tried to place the code in the Open and Load Subs
but no luck, i still get the error...

i'm desperate :)
i cant see whats wrong, (the worse part is, its probably something so simple)
anyways, here is my code for my Open (load is empty)
hope you guys can help me out =0)

Private Sub Form_Open(Cancel As Integer)
On Error GoTo Err_Form_Open
Dim LastRec
If Not (IsNull(Me.OpenArgs) = True) Then
Number = Me.OpenArgs 'number is a global var
'Me.filter = "RO = " & Number
'Me.FilterOn = True
End If
DoCmd.ApplyFilter ROFilter, "RO =" & Number
'find last rec number
DoCmd.GoToRecord , , acLast
LastRec = CurrentRecord
'move to first rec
DoCmd.GoToRecord , , acFirst
'disable nav buttons
Me![Previous].Enabled = False
If CurrentRecord = LastRec Then
Me![Next].Enabled = False
End If
Exit_Form_Open:
Exit Sub
Err_Form_Open:
MsgBox Error$
Resume Exit_Form_Open
End Sub

what ever i try i always get a message saying that the
filter was canceled
please help me
thank you
 
no luck :(
i cant get it to work
i keep getting an error

when i try your code,
DoCmd.ApplyFilter ROFilter, "RO =" & Number

i get a "The ApplyFilter action was canceled" error
i looked and the "allowFilters" property is set to yes
i've tried to place the code in the Open and Load Subs
but no luck, i still get the error...

i'm desperate :)
i cant see whats wrong, (the worse part is, its probably something so simple)
anyways, here is my code for my Open (load is empty)
hope you guys can help me out =0)

Private Sub Form_Open(Cancel As Integer)
On Error GoTo Err_Form_Open
Dim LastRec
If Not (IsNull(Me.OpenArgs) = True) Then
Number = Me.OpenArgs 'number is a global var
'Me.filter = "RO = " & Number
'Me.FilterOn = True
End If
DoCmd.ApplyFilter ROFilter, "RO =" & Number
'find last rec number
DoCmd.GoToRecord , , acLast
LastRec = CurrentRecord
'move to first rec
DoCmd.GoToRecord , , acFirst
'disable nav buttons
Me![Previous].Enabled = False
If CurrentRecord = LastRec Then
Me![Next].Enabled = False
End If
Exit_Form_Open:
Exit Sub
Err_Form_Open:
MsgBox Error$
Resume Exit_Form_Open
End Sub

what ever i try i always get a message saying that the
filter was canceled
please help me
thank you
 
oops, sorry about the double post

anyways... bump
i still haven't figured it out

please help
(tell me if i'm not being clear, i really need this to work
or the whole program is scrap)
thank you
 
Eric
What is it you are trying to do with this line

DoCmd.ApplyFilter ROFilter, "RO =" & Number

It seems that you are trying to apply a Stored query as a filter AND use a Where condition. I am not sure if this is your error but I am pretty sure you can't do both.

Next I would put a break in this code and see what line actually causes the error.

As an example I have an Invoice form that is used by various departments. I append various Prefixes (called id-string) to the UIDs of each Invoice in order to discern them from each other. I can limit the Invoice form to only Scientific Invoices useing...

DoCmd.ApplyFilter , "id_string = '" & Me.id_string & "'"

Or limit the Invoices to those that refer only to a particular Quote Number ...

DoCmd.ApplyFilter , "file_no = " & locQuoteNumber

HTH
Chris
 
hi chris
the line
DoCmd.ApplyFilter ROFilter, "RO =" & Number
was just a desperate attempt to see if it would work
i forgot to fix it before posting...
anyways
my actual line is
DoCmd.ApplyFilter , "RO =" & Number
where Number is a stored number like 221

oh my god, i just figured it out as i'm writing this
i forgot to "box in" my number with single quotes!!!!

it's working now, thanks!
so much time wasted on such a little detail
oh well =0)

the proper line is
DoCmd.ApplyFilter , "RO ='" & Number & "'"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top