Visual Basic ("Run-Time Error 13" Type Mismatch)?

hi, i'm having a hard time with vb 6. i'm creating a database linked to Microsoft Access. here's my code:

Private Sub ListStudent()

If Not rs.EOF Then



Do While Not rs.EOF

Set l = ListView1.ListItems.Add(, , rs!StudName)

l.SubItems(1) = rs!StudNum

l.SubItems(2) = rs!StudCourse (this line has the error, a tool tip text says that rs!StudCourse=null)

l.SubItems(3) = rs!StudAdd





End If

End Sub


Private Sub Form_Load()

Call Open_Conn

Set rs = cn.Execute("Select * from Table1")


Call Close_Conn

End Sub

6 Answers

  • 1 decade ago
    Favorite Answer

    Try replacing the line with:

    l.SubItems(2) = IIf(IsNull(rs!StudCourse, "", CStr(rs!StudCourse)))

    Basically, what this does is, first it figures out if rs!StudCourse is Null. If it is, then it assigns the empty string "" to l.SubItems(2), otherwise, it gives out a string converted value of rs!StudCourse.

    Source(s): Experience
    • Commenter avatarLogin to reply the answers
  • A null value from a recordset usually indicates that (a) you have misnamed the data field "StudCourse", or (b) there is a null value in the actual field "StudCourse", which cannot be assigned to I.SubItems(2). If (a) is the issue, simply correcting the fieldname should fix the code. If (b) is the issue, try replacing:

    l.SubItems(2) = rs!StudCourse


    l.SubItems(2) = iif(isnull(rs!StudCourse),"",rs!StudCourse)

    That should assign an empty string instead in the case where StudCourse is null.

    • Commenter avatarLogin to reply the answers
  • 1 decade ago

    Hi, gail

    There are 3 step to repair run time 13 error

    My friend had the same problem with you. I am sure your computer has registry problems.It is very easy to repair run time 13 error. you just need 3 steps:

    1: Download a registry cleaner and install it.

    2: Open the registry cleaner and scan you computer for free.

    3: Click fix button and you done.

    Download the top run time 13 error repair tool here:

    • Commenter avatarLogin to reply the answers
  • Anonymous
    1 decade ago

    Fix the data. Make sure the table does not have null values in the StudCourse field.

    • Commenter avatarLogin to reply the answers
  • How do you think about the answers? You can sign in to vote the answer.
  • Anonymous
    1 decade ago

    A type mismatch usually occurs when you are assigning or comparing two variables or values of different types. For instance trying to put a float into an integer. Check all of your compare and assignment statements again, you should be able to find it.

    • Commenter avatarLogin to reply the answers
  • Karen
    Lv 4
    4 years ago

    Dim Val as Integer If IsNumber(Cbo2.Text) then Val = CType(Cbo2.Text, Integer) End If then use Val instead of cbo2.text

    • Commenter avatarLogin to reply the answers
Still have questions? Get your answers by asking now.