Error Handling

neilmcmor

Registered User.
Local time
Today, 16:05
Joined
Aug 9, 2007
Messages
70
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
 
Why not use:
Code:
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")
[color=red]If IsNumeric(answer) Then[/color]
   If Trim(answer & "") <> "" Then
      stLinkCriteria = "spin=" & answer & ""
      DoCmd.OpenForm stDocName, , , stLinkCriteria
   End If
[color=red]Else
   MsgBox "You didn't enter a number!  Please try again.", vbExclamation, "Entry Error"
   Exit Sub
End If[/color]

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
 
Thanks

Thanks bob. worked great
 

Users who are viewing this thread

Back
Top Bottom