Handling errors

  • Thread starter Thread starter Mike Waters
  • Start date Start date
M

Mike Waters

Hello,
In my database I have a section of code that gets a
number from the user, and then filters the form
acordingly. The problem is if the user clicks Cancel, I
get an error. Is there anyway to stop this. The section
of code I'm using is below.

me.filter="[PO#]=[PO}"

This brings up a box for input where the user can put in
the PO, and then filters it. If you leave it blank, and
click ok, it filters for anything without a PO. But if
you hit cancel, I get an error. If anyone can help
please let me know.

Thank You,
Mike
 
Mike Waters said:
Hello,
In my database I have a section of code that gets a
number from the user, and then filters the form
acordingly. The problem is if the user clicks Cancel, I
get an error. Is there anyway to stop this. The section
of code I'm using is below.

me.filter="[PO#]=[PO}"

This brings up a box for input where the user can put in
the PO, and then filters it. If you leave it blank, and
click ok, it filters for anything without a PO. But if
you hit cancel, I get an error. If anyone can help
please let me know.

Don't use a parameter pop-up. You don't have any control then.

Dim RetVal as String
RetVal = InputBox("Please Enter PO #")

If RetVal = "" Then
'user hit Cancel
ElseIf IsNumeric(RetVal) = True Then
Me.Filter="[PO#]=" & RetVal
Else
MsgBox "Not a valid entry"
End If
 
Thanks for the reply. I tried adding the code you
listed, but now I get 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 can't figure out why I'm getting the error.

Thanks,
Mike
-----Original Message-----
Mike Waters said:
Hello,
In my database I have a section of code that gets a
number from the user, and then filters the form
acordingly. The problem is if the user clicks Cancel, I
get an error. Is there anyway to stop this. The section
of code I'm using is below.

me.filter="[PO#]=[PO}"

This brings up a box for input where the user can put in
the PO, and then filters it. If you leave it blank, and
click ok, it filters for anything without a PO. But if
you hit cancel, I get an error. If anyone can help
please let me know.

Don't use a parameter pop-up. You don't have any control then.

Dim RetVal as String
RetVal = InputBox("Please Enter PO #")

If RetVal = "" Then
'user hit Cancel
ElseIf IsNumeric(RetVal) = True Then
Me.Filter="[PO#]=" & RetVal
Else
MsgBox "Not a valid entry"
End If


--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com



.
 
Mike Waters said:
Thanks for the reply. I tried adding the code you
listed, but now I get 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 can't figure out why I'm getting the error.

I copied your code exactly into a test form and it worked for me (Access 97).
You could perhaps try using the Load event instead of Open.
 
Back
Top