Errors when trying to filter

M

mike waters

Hello,
a few weeks back I posted a message asking for help
when trying to filter a form with VB. I was given a
suggestion, and tried it, but for some reason I keep
getting an error message. It says run time error 2001:
You canceled the previous operation. Below is the exact
code how I have it:
Private Sub Form_Open(Cancel As Integer)
Dim RetVal As String
If More_Locations.Value = True Then
FormFooter.Visible = True
Else
FormFooter.Visible = False
End If
RetVal = InputBox("Enter PO")
If RetVal = "" Then
Me.FilterOn = False
ElseIf IsNumeric(RetVal) Then
Me.Filter = "[PO#]=" & RetVal
Me.FilterOn = True 'This is the line its stopping
on
Else
MsgBox "Invalid Entry"

End If

End Sub

I've treid everything I can think of. I've tried putting
a button on my form to filter using the code here, and I
get the same error message. I only get the messaage when
I enter a valid number. It works fine if I enter an
invalid selection. If anyone has any suggestion please
let me know.

Thank You,
Mike Waters
 
D

Denny

What is the datatype of your field PO#?

I could only duplicate your error, if I used the following
code to filter a field datatype of Text.

Me.Filter = "[Second]=" & "2"

However I could duplicate it again if I changed the type
to Number, but had the following code where 2 is a valid
value in field 'Second' in my table. I would check the
data type of your field PO#, and see that the Filter
statement is written correctly for the datatype.

Me.Filter = "[Second]=" & "'2'"
 
M

mike waters

Thanks for the reply. The current field type is text
although currently only numerical data is entered into
it. If I understand what you are saying correctly, I'll
try changing it to a numerical field and see if it works.
Thanks for the help.

Mike
-----Original Message-----
What is the datatype of your field PO#?

I could only duplicate your error, if I used the following
code to filter a field datatype of Text.

Me.Filter = "[Second]=" & "2"

However I could duplicate it again if I changed the type
to Number, but had the following code where 2 is a valid
value in field 'Second' in my table. I would check the
data type of your field PO#, and see that the Filter
statement is written correctly for the datatype.

Me.Filter = "[Second]=" & "'2'"
-----Original Message-----
Hello,
a few weeks back I posted a message asking for help
when trying to filter a form with VB. I was given a
suggestion, and tried it, but for some reason I keep
getting an error message. It says run time error 2001:
You canceled the previous operation. Below is the exact
code how I have it:
Private Sub Form_Open(Cancel As Integer)
Dim RetVal As String
If More_Locations.Value = True Then
FormFooter.Visible = True
Else
FormFooter.Visible = False
End If
RetVal = InputBox("Enter PO")
If RetVal = "" Then
Me.FilterOn = False
ElseIf IsNumeric(RetVal) Then
Me.Filter = "[PO#]=" & RetVal
Me.FilterOn = True 'This is the line its stopping
on
Else
MsgBox "Invalid Entry"

End If

End Sub

I've treid everything I can think of. I've tried putting
a button on my form to filter using the code here, and I
get the same error message. I only get the messaage when
I enter a valid number. It works fine if I enter an
invalid selection. If anyone has any suggestion please
let me know.

Thank You,
Mike Waters

.
.
 
M

mike waters

I was wrong in my last post, there are records in the PO#
field that have text in them. Since i noticed this, I do
need to change my if structure so it will accept things
other then numbers, but thats kind of easy. The question
I have then is what is the best way to convert the numbers
to text, if I would need to do that to get it to work.

Mike
-----Original Message-----
What is the datatype of your field PO#?

I could only duplicate your error, if I used the following
code to filter a field datatype of Text.

Me.Filter = "[Second]=" & "2"

However I could duplicate it again if I changed the type
to Number, but had the following code where 2 is a valid
value in field 'Second' in my table. I would check the
data type of your field PO#, and see that the Filter
statement is written correctly for the datatype.

Me.Filter = "[Second]=" & "'2'"
-----Original Message-----
Hello,
a few weeks back I posted a message asking for help
when trying to filter a form with VB. I was given a
suggestion, and tried it, but for some reason I keep
getting an error message. It says run time error 2001:
You canceled the previous operation. Below is the exact
code how I have it:
Private Sub Form_Open(Cancel As Integer)
Dim RetVal As String
If More_Locations.Value = True Then
FormFooter.Visible = True
Else
FormFooter.Visible = False
End If
RetVal = InputBox("Enter PO")
If RetVal = "" Then
Me.FilterOn = False
ElseIf IsNumeric(RetVal) Then
Me.Filter = "[PO#]=" & RetVal
Me.FilterOn = True 'This is the line its stopping
on
Else
MsgBox "Invalid Entry"

End If

End Sub

I've treid everything I can think of. I've tried putting
a button on my form to filter using the code here, and I
get the same error message. I only get the messaage when
I enter a valid number. It works fine if I enter an
invalid selection. If anyone has any suggestion please
let me know.

Thank You,
Mike Waters

.
.
 

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

Similar Threads


Top