Type mismatch error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Knowlton
    New Member
    • Feb 2011
    • 75

    Type mismatch error

    I'm getting an error 13 - Type Mismatch with the following code:

    Code:
    MsgBox "Total trip miles = " & lngTripMiles & _
                    " and the status miles total = " _
                    & (lngLoadedMiles + lngEmptyMiles + lngBobtailMiles) & ".", "Trip calculation error"
    All the variables are defined as Long. What am I doing wrong?
    Thanks
  • zmbd
    Recognized Expert Moderator Expert
    • Mar 2012
    • 5501

    #2
    that is because "Trip calculation error"
    is in the position for the button/icon/msgtype

    IMHO: It's usually better to build your string first and then insert it into the function.

    In anycase, add another comma before the "Trip...", and I prefer to specify the button type; thus, you now have:
    Code:
    MsgBox "Total trip miles = " & lngTripMiles & _
                    " and the status miles total = " _
                    & (lngLoadedMiles + lngEmptyMiles + lngBobtailMiles) & ".", vbOKOnly, "Trip calculation error"
    IMHO Ideally you would
    Code:
    (...)dim strMsg as String
    strMsg = "Total trip miles = " & lngTripMiles & _
                    " and the status miles total = " _
                    & (lngLoadedMiles + lngEmptyMiles + lngBobtailMiles) & "."
    '
    MsgBox strMsg,vbOKOnly,"Trip calculation error"
    (...)
    This way if you need to you can debug.print the string.

    Comment

    • Knowlton
      New Member
      • Feb 2011
      • 75

      #3
      Thanks! I wasn't paying close enough attention to the prompts when I created it.

      Comment

      • zmbd
        Recognized Expert Moderator Expert
        • Mar 2012
        • 5501

        #4
        if I had a dollar... (^_^)

        Comment

        Working...