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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

error handling 1

Status
Not open for further replies.

neilmcmor

Technical User
Aug 9, 2007
30
GB
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
 
You may want to look at using the IsNumeric function to test the value entered before passing it as a parameter to the OpenForm method.

Something like:

Code:
answer = InputBox("Enter the Spin Number you wish to search for", "Find on Spin")

if isnumeric(answer) then
    'Open the form
else
    MsgBox "The value entered must be numeric.",vbExclamation,"Input Error."
End If

Ed Metcalfe.

Please do not feed the trolls.....
 
You're welcome Neil. :)

Ed Metcalfe.

Please do not feed the trolls.....
 
neilmcmor

Is this accesptable 1132d2 or 1132e2

So if scientific notation should not be permitted then

Code:
answer = InputBox("Enter the Spin Number you wish to search for", "Find on Spin")

if isnumeric(answer & "e0") then
    'Open the form
else
    MsgBox "The value entered must be numeric.",vbExclamation,"Input Error."
End If

You may also include a min and max range
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top