+ Reply to Thread
Results 1 to 22 of 22

Problem with understanding Type mismatch error?

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    05-08-2015
    Location
    Seattle, WA USA
    MS-Off Ver
    Excel 2013, 2016, Mac 2016
    Posts
    629

    Problem with understanding Type mismatch error?

    Hi all

    I am counting the days until Tsjallie returns from his vacation (He helps me on this project). In the mean time I am wondering if anyone can help me in my understanding of the Type mismatch Error? I understand that I need to match txt and numbers. I kinda understand that the data needs to come from like tables. I am wondering why I get the error on a seemingly simple sub as below;

    Screen Shot 2016-03-21 at 11.34.42 AM.png


    Screen Shot 2016-03-21 at 11.35.19 AM.png

    Maybe someone could suggest some reading that I could do that might clear it up in my head?

    I will attach the file if you want to take a look?
    Attached Files Attached Files
    Last edited by u3rick; 03-21-2016 at 03:31 PM.
    Have a great day!

    u3rick

  2. #2
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: Problem with understanding Type mismatch error?

    A lot of us are not able to see images. Can you let us know which routine you are running when you get the error and on what line the error is.
    1N73LL1G3NC3 15 7H3 4B1L17Y 70 4D4P7 70 CH4NG3 - 573PH3N H4WK1NG
    You don't have to add Rep if I have helped you out (but it would be nice), but please mark the thread as SOLVED if your issue is resolved.

    Tom

  3. #3
    Forum Contributor
    Join Date
    05-08-2015
    Location
    Seattle, WA USA
    MS-Off Ver
    Excel 2013, 2016, Mac 2016
    Posts
    629

    Re: Problem with understanding Type mismatch error?

    gmr4evr1

    Sorry I didn't know that, the red code is where the error type mismatch is and it happens when it tries to fill in data in a new Booking Form. Hope that helps, if not let me know and I will try again.

    Private Sub txtPropIdSA_Change()
    
    Dim tblProperties As ListObject
    Dim tblGuestStays As ListObject
    Dim RecIdx As Integer
    
          FormEventsEnabled = False 'To prevent firing control events and looping
          
          Set tblGuestStays = Worksheets("GuestStays").ListObjects("tblGuestStays")
          Set tblProperties = Worksheets("Properties").ListObjects("tblProperties")
          
          With tblGuestStays
          
          RecIdx = Application.Match(CDbl(Me.txtPropIdSA), .ListColumns("PropertyId").DataBodyRange, 0)
    
                Me.txtStayAmtSA = .ListColumns("MonthlyRent").DataBodyRange(RecIdx)
                Me.txtProAmtSA = .ListColumns("ProrateAmt").DataBodyRange(RecIdx)
                Me.txtDepAmtSA = .ListColumns("SecurityDeposit").DataBodyRange(RecIdx)
          End With
          
          FormEventsEnabled = True
          Set tblGuestStays = Nothing 'Clean up
          Set tblProperties = Nothing 'Clean up
          
    End Sub

  4. #4
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: Problem with understanding Type mismatch error?

    Getting warmer. You have a train-load of code in that workbook. I looked through it and can not find that code. Where exactly is it located and how is it triggered?

  5. #5
    Forum Contributor
    Join Date
    05-08-2015
    Location
    Seattle, WA USA
    MS-Off Ver
    Excel 2013, 2016, Mac 2016
    Posts
    629

    Re: Problem with understanding Type mismatch error?

    gmr4evr1

    Its triggered from the module mdlESReservation Sub and Case below.

    Sub HandleRightClick(ByVal Target As Range)
    '---------------------------------------------------------------------------------------
    ' Procedure : HandleRightClick  (1)
    ' Author    : Tsjallie
    ' Date      : 10/25, 2015
    ' Purpose   : Handles rightclicking a cell in the calendar
    ' History   : 10/28, 2015: Overhaul existing code
    '---------------------------------------------------------------------------------------
    Starts here and has a few cases

    Case Not Intersect(Target, ActiveSheet.ListObjects("tblCalendar").DataBodyRandg) Is Nothing

    Don't give up on me, I am a an advanced beginner!lool!

    It is triggered by picking vacant months in a property row and right clicking on it in the Calendar (Tsjallie Calendar) Sheet.
    Last edited by u3rick; 03-21-2016 at 05:43 PM.

  6. #6
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: Problem with understanding Type mismatch error?

    I hate to do this to you, but I get errors in other areas when I try to do things with your workbook (and there is A LOT going on in that workbook) so I can't even get to the error you are asking about. Maybe someone else can help, or you may have to wait until Tsjallie gets back.

  7. #7
    Forum Contributor
    Join Date
    05-08-2015
    Location
    Seattle, WA USA
    MS-Off Ver
    Excel 2013, 2016, Mac 2016
    Posts
    629

    Re: Problem with understanding Type mismatch error?

    gmr4evr1

    Thanks for trying! I am not much help as I don't know how to strip it down! Do you know anyplace I can get information on matching code in that way that might help in my general understanding of VBA?

    Thanks again!

  8. #8
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,645

    Re: Problem with understanding Type mismatch error?

    You've declared RecIdx as Integer, if Application.Match fails it will return an error value.

    So if Application.Match fails you will get a type mismatch because you are trying to assign an error value to an integer variable.

    Try declaring RecIdx as Variant and add code to check for an error.
    If posting code please use code tags, see here.

  9. #9
    Forum Contributor
    Join Date
    05-08-2015
    Location
    Seattle, WA USA
    MS-Off Ver
    Excel 2013, 2016, Mac 2016
    Posts
    629

    Re: Problem with understanding Type mismatch error?

    Norie


    I will try that! Why is it that the number that shows when I hover over the match Id # is the correct Id number?

    Thanks

  10. #10
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,645

    Re: Problem with understanding Type mismatch error?

    Hard to tell without running the code and there is no sub named txtPropIdSA_Change in the workbook you uploaded.

  11. #11
    Forum Contributor
    Join Date
    05-08-2015
    Location
    Seattle, WA USA
    MS-Off Ver
    Excel 2013, 2016, Mac 2016
    Posts
    629

    Re: Problem with understanding Type mismatch error?

    Norie

    Shoot I did remove for a bit but thought I attached version before I deleted sorry!

    Attached Files Attached Files

  12. #12
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,645

    Re: Problem with understanding Type mismatch error?

    There's still a lot of stuff missing, not just code either as there appears to be a lot of missing (or misnamed/misspelled?) controls etc.

    Also, in the sub txtPropIdSA_Change you have this,
             RecIdx = Application.Match(CDbl("mdlESReservation[PropertyId]"), .ListColumns("PropertyId").DataBodyRange, 0)
    which is kind of different to the code you've posted here.

  13. #13
    Forum Contributor
    Join Date
    05-08-2015
    Location
    Seattle, WA USA
    MS-Off Ver
    Excel 2013, 2016, Mac 2016
    Posts
    629

    Re: Problem with understanding Type mismatch error?

    Norie

    I was trying many things from many locations to match that Id number, that one didn't work and I forgot I didn't change it back to the original !:roll eyes:

    Sorry let me clean thing up a bit and I will put up a new version soon!

  14. #14
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,645

    Re: Problem with understanding Type mismatch error?

    No problem, try compiling (Debug>Compile VBAProject) it before uploading.

    When you compile all the undeclared/misnamed controls/variables will be highlighted, one by one unfortunately, and you can deal with them.

  15. #15
    Forum Contributor
    Join Date
    05-08-2015
    Location
    Seattle, WA USA
    MS-Off Ver
    Excel 2013, 2016, Mac 2016
    Posts
    629

    Re: Problem with understanding Type mismatch error?

    Norie

    Thanks, I was going to ask how I might clean up the mess!

  16. #16
    Forum Contributor
    Join Date
    05-08-2015
    Location
    Seattle, WA USA
    MS-Off Ver
    Excel 2013, 2016, Mac 2016
    Posts
    629

    Re: Problem with understanding Type mismatch error?

    Norie

    Here is a cleaned up version

    Thanks for any help!
    Attached Files Attached Files

  17. #17
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,645

    Re: Problem with understanding Type mismatch error?

    Just had a quick look and I notice your property codes are alphanumeric, not numeric, eg x BR 7650.

    In your code you are using CDbl on the textbox txtPropIdSA, CDbl is used to convert a text value to a double value, if possible.

    If you use CDbl with an alphanumeric value it will return an error, try removing CDbl.

    Something like this.
    Private Sub txtPropIdSA_Change()
        '---------------------------------------------------------------------------------------
        ' Procedure :txtPropIdSA_Change
        ' Author    : Tsjallie/Rick
        ' Date      :3/21/2016
        ' Purpose   : To fill frmStayActivity Accounting frame
        ' History   : New Code
        '---------------------------------------------------------------------------------------
        '
    Dim tblGuestStays As ListObject
    Dim RecIdx As Variant
    
    FormEventsEnabled = False    'To prevent firing control events and looping
    
        Set tblGuestStays = Worksheets("GuestStays").ListObjects("tblGuestStays")
    
        With tblGuestStays
    
            RecIdx = Application.Match(txtPropIdSA, .ListColumns("PropertyCode").DataBodyRange, 0)
            If Not IsError(RecIdx) Then
                Me.txtStayAmtSA = .ListColumns("MonthlyRate").DataBodyRange(RecIdx)
                Me.txtProAmtSA = .ListColumns("ProrateAmt").DataBodyRange(RecIdx)
                Me.txtDepAmtSA = .ListColumns("SecurityDeposit").DataBodyRange(RecIdx)
            End If
        End With
    
        FormEventsEnabled = True
        Set tblGuestStays = Nothing    'Clean up
    
    End Sub
    Note I've changed MonthlyRent to MonthlyRate as there's no MonthlyRent column in the table tblGuestStays.

  18. #18
    Forum Contributor
    Join Date
    05-08-2015
    Location
    Seattle, WA USA
    MS-Off Ver
    Excel 2013, 2016, Mac 2016
    Posts
    629

    Re: Problem with understanding Type mismatch error?

    Norie

    Thanks will work on this in the AM!

  19. #19
    Forum Contributor
    Join Date
    08-14-2013
    Location
    Florida
    MS-Off Ver
    Excel 2013
    Posts
    105

    Re: Problem with understanding Type mismatch error?

    I just noticed monthlyrent as well. I also (instead of variant)... changed RecIdx to Long and then just used a Clng cast
    You could do the same with Cint

    RecIdx = CLng(Application.Match(CDbl(txtPropIdSA), .ListColumns("PropertyCode").DataBodyRange, 0))
    'or
    RecIdx = CInt(Application.Match(CDbl(txtPropIdSA), .ListColumns("PropertyCode").DataBodyRange, 0))

  20. #20
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,645

    Re: Problem with understanding Type mismatch error?

    You should declare RecIdx as Variant so if there is a problem with Application.Match the code would break.

  21. #21
    Forum Contributor
    Join Date
    05-08-2015
    Location
    Seattle, WA USA
    MS-Off Ver
    Excel 2013, 2016, Mac 2016
    Posts
    629

    Re: Problem with understanding Type mismatch error?

    Norie and Kalithro

    Thanks for both your input. I have figured out what was causing the problem. I was calling the wrong sheet! the info exists on two sheets, but the propertyId I was matching was not on the sheet I was checking. This caused it to error 2042. Thats why I could see the right Id when I watch, but it still error or show type mismatch.

    Would have never figured that without your guys help!

  22. #22
    Forum Contributor
    Join Date
    05-08-2015
    Location
    Seattle, WA USA
    MS-Off Ver
    Excel 2013, 2016, Mac 2016
    Posts
    629

    Re: Problem with understanding Type mismatch error?

    Kalithro

    Yes, I should change the form, I make that mistake every time I use that textbook!

    Thanks for your help!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Problem with TabStrip code - Error Type Mismatch
    By imzhakmaya in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-08-2014, 08:14 AM
  2. [SOLVED] How to fix run-time error '13' type mismatch problem for my audit trail program?
    By ohlalayeah in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-30-2012, 11:37 PM
  3. [SOLVED] Merged cells cause "Runtime error 13 type mismatch" problem
    By Ralph Malph in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-07-2006, 08:55 AM
  4. Array problem: Key words-Variant Array, single-element, type mismatch error
    By davidm in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-09-2005, 01:54 AM
  5. Array problem: Key words-Variant Array, single-element, type mismatch error
    By davidm in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-08-2005, 12:30 AM
  6. [SOLVED] Help: Compile error: type mismatch: array or user defined type expected
    By lvcha.gouqizi in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-31-2005, 05:05 PM
  7. [SOLVED] Type mismatch error problem when dealing with Strings
    By David Goodall in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-30-2005, 09:05 AM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1