Results 1 to 11 of 11
  1. #1
    Join Date
    Mar 2004
    Location
    Atlanta, GA
    Posts
    58

    Unanswered: Error 13. Type Mismatch

    When I run this code I am getting a type mismatch error.

    Code:
    If Not IsNull(Me.cboMake) And (Me.txtVIN) Then
            Dim strStockNbr As String
            Dim strLeft As String
            Dim strRight As String
            strLeft = Left(cboMake, 1)
            strRight = Right(txtVIN, 5)
            strStockNbr = strLeft & strRight
            Me!txtStockNumber = strStockNbr
        Else
        End If

  2. #2
    Join Date
    May 2004
    Posts
    19
    Check the values of "cboMake" and "txtVIN"

  3. #3
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    What line does it error on?

    I'm curious as to what "AND (Me.txtVIN)" is supposed to evaluate.
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  4. #4
    Join Date
    Mar 2004
    Location
    Atlanta, GA
    Posts
    58
    If cboMake or txtVIN is null I don't want the sub to run.

  5. #5
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    In that case you need to rephrase your if statement:

    If Not IsNull(Me.cboMake) And Not IsNull(Me.txtVIN)
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  6. #6
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    he also gets mad when people use left() on a string.
    left$() is faster.

    left() is for variants (and like anything associated with variants it is slooooow)

    izy
    currently using SS 2008R2

  7. #7
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    Haha, I almost forgot about that one.

    You're like the damn monkey on the monkey's back!!!


    j/k, we love you Izy.

    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  8. #8
    Join Date
    Mar 2004
    Location
    Atlanta, GA
    Posts
    58
    Thanks. That worked.

  9. #9
    Join Date
    Jun 2009
    Posts
    3
    i am also getting the same error when i run following code. strange is- same code works fine for some worksheets and for some worksheets error msg comes after some lines and when i restart from that cell it works fine. i checked the cell formatting already.

    Sub Macro2()
    '
    ' Macro2 Macro
    ' Macro recorded 6/2/2009 by vharyan
    Dim k
    k = 0
    Do While (k < 1000)

    shubham
    k = k + 1
    Loop

    End Sub
    Sub shubham()
    Dim i
    Dim j
    i = 0
    j = 0
    Do Until (ActiveCell.Offset(j, -2).Value = "")

    i = ActiveCell.Offset(j, -2).Value + i
    j = j + 1
    ActiveCell.Offset(0, 1).Value = i
    Loop

    j = j + 1

    ActiveCell.Offset(j, 0).Range("A1").Select
    Do Until (ActiveCell.Offset(j, -2).Value > 0)

    j = j + 1
    ActiveCell.Offset(j, 0).Range("A1").Select
    If j < 1000 Then Exit Do


    Loop


    End Sub

  10. #10
    Join Date
    Feb 2002
    Posts
    108
    Quote Originally Posted by izyrider
    he also gets mad when people use left() on a string.
    left$() is faster.

    left() is for variants (and like anything associated with variants it is slooooow)

    izy
    help me understand the difference in left() and left$().
    I have hundreds of left() in my programs, and am always looking for speed

  11. #11
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    left(MyVariable, 1) doesn't assume what kind of data type MyVariable will be. So before it can actually do the work of slicing off the first character, it first has to find out what kind of data is in MyVariable, then cast it to a string, THEN actually perform the left() operation.

    left$(MyVariable, 1) forces you to pass a string. It will error if MyVariable is anything but a string. In this way, it can avoid the whole type checking/conversion spiel that left() has to go through.
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •