View Full Version : Error Handling


neilmcmor
08-11-2007, 04:40 AM
Hope someone can help. The attached code works fine however I am having problems with the Error part. The data is numerical and should non numerical data be placed in the search box it gives up the correct message EXCEPT when a non numerical charachter is placed first in the string. ie 123rt4 gives up coerrect error message, e2345 does not. what I get instead is an input box requesting a parameter. Any ideas.

Private Sub cmdFind_Click()


On Error GoTo Error_CmdFindAnError

Dim answer As String
Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Prisoner_Details"
answer = InputBox("Enter the Spin Number you wish to search for", "Find on Spin")
If Trim(answer & "") <> "" Then
stLinkCriteria = "spin=" & answer & ""
DoCmd.OpenForm stDocName, , , stLinkCriteria
End If


Exit_CmdFind:

Exit Sub

Error_CmdFindAnError:

MsgBox "You've have not entered a Number. " _
& "Spin Number is Numerical!.", vbOKOnly, "Error"


Resume Exit_CmdFind

End Sub

boblarson
08-11-2007, 06:32 AM
Why not use:

Private Sub cmdFind_Click()


On Error GoTo Error_CmdFindAnError

Dim answer As String
Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Prisoner_Details"
answer = InputBox("Enter the Spin Number you wish to search for", "Find on Spin")
If IsNumeric(answer) Then
If Trim(answer & "") <> "" Then
stLinkCriteria = "spin=" & answer & ""
DoCmd.OpenForm stDocName, , , stLinkCriteria
End If
Else
MsgBox "You didn't enter a number! Please try again.", vbExclamation, "Entry Error"
Exit Sub
End If

Exit_CmdFind:

Exit Sub

Error_CmdFindAnError:

MsgBox "You've have not entered a Number. " _
& "Spin Number is Numerical!.", vbOKOnly, "Error"


Resume Exit_CmdFind

End Sub

neilmcmor
08-11-2007, 06:43 AM
Thanks bob. worked great