Hello again,
Its been a while since I've asked a question, I've been learning steadily reading the How To's and the questions in this forum, as well as reading my Access VBA and Access bibles till they are now in tatters!.
I'm stuck with understanding the error handling process by VB6.5 (in particular for MSAccess 2003).
The following code is a test code only, so that I could understand things before I go on to something more meaty. It is probably the 5th incarnation or attempt and as you can see I have resorted to If..Then..Else and a SubFunction to try and handle this type of error. The error I'm referring to is the nasy Err 13 Data Type Mismatch error which occurs when I deliberately enter a non numeric character in the text box on the form. (The from has one command button and one text box)
Despite trying to handle the error with a very simple error handle subroutine in my previous attempt:
No matter what I do the Built-In Error Message (as unhelpful as they are :P) still occur.
Both sets of code of course break at the "aNumber = CDbl(Me.Text1)" line.
Would really appreciate it if anyone can help with this :)
JP
Its been a while since I've asked a question, I've been learning steadily reading the How To's and the questions in this forum, as well as reading my Access VBA and Access bibles till they are now in tatters!.
I'm stuck with understanding the error handling process by VB6.5 (in particular for MSAccess 2003).
The following code is a test code only, so that I could understand things before I go on to something more meaty. It is probably the 5th incarnation or attempt and as you can see I have resorted to If..Then..Else and a SubFunction to try and handle this type of error. The error I'm referring to is the nasy Err 13 Data Type Mismatch error which occurs when I deliberately enter a non numeric character in the text box on the form. (The from has one command button and one text box)
Code:
Sub Command0_Click() Dim aNumberbox As Double Dim NotANumber As Variant aNumberbox = 0 NotANumber = CVErr(13) aNumberbox = CheckData(Me.Text1) If IsError(aNumberbox) Then Select Case aNumberbox Case NotANumber MsgBox "Error: not a number." Case Else MsgBox "Unknown Error." End Select Else aNumberbox = Me.Text1 MsgBox ("You entered the number " & aNumberbox) MsgBox ("Why not try it again?") End If End Sub Function CheckData(aNumberbox As Integer) As Integer Dim NotANumber As Integer If Not IsNumeric(aNumberbox) Then CheckData = NotANumber End If End Function
Code:
Sub Command0_Click() Dim aNumber As Double On Error GoTo ErrorHandle aNumber = CDbl(Me.Text1) ExitHere: MsgBox ("You entered the number " & aNumber) MsgBox ("Why not try it again?") ErrorHandle: MsgBox ("Please enter a number.") Resume ExitHere End Sub
Both sets of code of course break at the "aNumber = CDbl(Me.Text1)" line.
Would really appreciate it if anyone can help with this :)
JP
Comment