Type mismatch error 13? 
Author Message
 Type mismatch error 13?

Hi, I keep getting the error message type mismatch 13 when I enter in
characters instead of numbers.  I'm trying to display my own error
message instead so the program won't stop. Can anyone please help. The
code is below. Thank you.

Private Sub cmdSearch_Click()
Dim intID As Integer

'Get the student ID and set it to intID
    intID = InputBox("Enter a Student's ID", "Get ID")
'If an error occurs go to HandleError
    On Error GoTo HandleError
'Refresh the database and move to the first record
'find the first match to intID in database
    frmStudents!datStudents.Refresh
    frmStudents!datStudents.Recordset.MoveFirst
    frmStudents!datStudents.Recordset.FindFirst "StuID = " & intID
'If no match found then display error message and clear all
'text box fields
    If frmStudents!datStudents.Recordset.NoMatch Then
        MsgBox "ID not found in database", _
            vbOKOnly, "ID Not Found Error"
        txtInstrID = ""
        txtName = ""
        txtRank = ""
        txtAddress = ""
        txtCity = ""
        txtState = ""
        txtPhone = ""
        txtExperience = ""
        txtZip = ""
    End If

HandleError:
'Get the error title
    strErrTitle = Err & " " & Error$
    Select Case Err
'If error = 3314 then display error message
        Case 13
            MsgBox "You need to enter in numbers only for student's ID",
_
            vbQuestion, strErrTitle

    End Select
'Execute the next statement after On Error above
        Resume Next
End Sub



Wed, 03 Jul 2002 03:00:00 GMT  
 Type mismatch error 13?
Try this:

Dim strID as String

strID = InputBox("Enter a Student's ID", "Get ID")

if len(strID) =0 then
    ' User canceled or didn't input anything.
    Exit Sub
End If

intID = CInt(strID)


Quote:
> Hi, I keep getting the error message type mismatch 13 when I enter in
> characters instead of numbers.  I'm trying to display my own error
> message instead so the program won't stop. Can anyone please help. The
> code is below. Thank you.

> Private Sub cmdSearch_Click()
> Dim intID As Integer

> 'Get the student ID and set it to intID
>     intID = InputBox("Enter a Student's ID", "Get ID")
> 'If an error occurs go to HandleError
>     On Error GoTo HandleError
> 'Refresh the database and move to the first record
> 'find the first match to intID in database
>     frmStudents!datStudents.Refresh
>     frmStudents!datStudents.Recordset.MoveFirst
>     frmStudents!datStudents.Recordset.FindFirst "StuID = " & intID
> 'If no match found then display error message and clear all
> 'text box fields
>     If frmStudents!datStudents.Recordset.NoMatch Then
>         MsgBox "ID not found in database", _
>             vbOKOnly, "ID Not Found Error"
>         txtInstrID = ""
>         txtName = ""
>         txtRank = ""
>         txtAddress = ""
>         txtCity = ""
>         txtState = ""
>         txtPhone = ""
>         txtExperience = ""
>         txtZip = ""
>     End If

> HandleError:
> 'Get the error title
>     strErrTitle = Err & " " & Error$
>     Select Case Err
> 'If error = 3314 then display error message
>         Case 13
>             MsgBox "You need to enter in numbers only for student's ID",
> _
>             vbQuestion, strErrTitle

>     End Select
> 'Execute the next statement after On Error above
>         Resume Next
> End Sub



Wed, 03 Jul 2002 03:00:00 GMT  
 Type mismatch error 13?

Quote:

>I keep getting the error message type mismatch 13 when I enter in
>characters instead of numbers.

The inputbox returns a string, the error occurs because it is trying to place a
string into your variable which has been declared as an integer.

The Inputbox is not the best choice for something like this, (You might design
a small form with a textbox and command button for your input).

Then you could check the contents before any error occurs.

If Not IsNumeric(Text1.Text) then
         MsgBox "You need to enter in numbers only for student'sID",
vbExclamation
          text1.setfocus
Else
         ' put code to check for file here

End If



Thu, 04 Jul 2002 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Type Mismatch Error 13

2. Using CurrentDB() receives Type Mismatch Error 13

3. Type mismatch error 13?

4. Type Mismatch error 13

5. Help!!! Please, Type Mismatch error 13

6. Type Mismatch Error 13

7. Passing a Recordset to function gives Type mismatch (error 13)

8. Worked fine yesterday, today I get Error 13 Type Mismatch errors

9. Error 13: Type Mismatch error

10. Type Mismatch Run-Time error 13

11. type mismatch error '13'????

12. Type mismatch, run-time error #13

 

 
Powered by phpBB® Forum Software