+ Reply to Thread
Results 1 to 12 of 12

Type Mismatch Error Populating a userform

  1. #1
    Registered User
    Join Date
    03-18-2017
    Location
    Kamloops, BC Canada
    MS-Off Ver
    Office 2013
    Posts
    7

    Type Mismatch Error Populating a userform

    I'm a super rookie at excel vba coding, about a week in. LOL. But i'm trying to self teach. I'm currently having a problem with populating a user form. I'm sure the answer is simple but I've been staring at it for 2 days and finally had the courage to ask for help.

    Problem: when I put in a ticket # and press search, i want the userform to populate. But when I try to run it, a type mismatch occurs. I've tried setting the text box's as integer or string and change the source in the worksheet to the respected type but then a invalid qualifier occurs.

    whats funny is I tried to simplify it, to test the code and it works so I'm not sure what I'm doing wrong.

    PHP Code: 
    Option Explicit
    Private Sub cbSearch_Click()

    Dim vResult

    'not sure if these are needed or not

    '
    Dim TextBox2 As Integer

    'Dim TextBox9 As Integer

    '
    Dim TextBox4 As String

    vResult 
    Application.CountIf(Worksheets("Journal").Range("A2:A10000"), Me.TextBox1.Value)
    If 
    vResult 0 Then

     
    'Error occurs here. "Could not set the Value properly. type mismatch. But when I try to set it(TextBox2, TextBox9, etc..)
     '
    as a string or Integer it comes back as invalid qualifier
    TextBox2
    .Value Application.VLookup(Me.TextBox1.ValueSheets("Journal").Range("A:BA"), 14False)
    TextBox9.Value Application.VLookup(Me.TextBox1.ValueSheets("Journal").Range("A:BA"), 15False)
    TextBox4.Value Application.VLookup(Me.TextBox1.ValueSheets("Journal").Range("A:BA"), 5False)

    'I also want the data to be imported to the userform to check the checkbox if it applies. I used 1 for true and 0 for false
    CheckBox1.Value = Application.VLookup(Me.TextBox1.Value, Sheets("Journal").Range("A:BA"), 30, False)
    CheckBox2.Value = Application.VLookup(Me.TextBox1.Value, Sheets("Journal").Range("A:BA"), 31, False)

    Else

    MsgBox "No match found. Please try again."
    End If

    End Sub 
    Wow! soooo much red. haha it doesn't look like that in VBA Editor :/
    Attached Files Attached Files
    Last edited by Mack1981; 03-19-2017 at 01:38 PM. Reason: Edit to comply with forum rules. My Bad. I'm new. Hope this is right

  2. #2
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,014

    Re: Type Mismatch Error Populating a userform

    Here is some sample code that you can refer to to get you going on your way.

    Your existing code is not far off, but after studying this small project you should understand what changes need to be made.
    Hope this helps.

    Please Login or Register  to view this content.


    Come back and ask more questions as needed.
    Attached Files Attached Files

  3. #3
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Type Mismatch Error Populating a userform

    You are making your code to complicated.

    You need to stop work for now so I can show you how to do this in a much simpler and clearer way.

    Unfortunately I cannot help you at this time because you have not inserted code tags.

    I have your code ready to post.


    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Click on Edit to open your thread, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)
    Last edited by mehmetcik; 03-18-2017 at 04:13 PM.
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

  4. #4
    Registered User
    Join Date
    03-18-2017
    Location
    Kamloops, BC Canada
    MS-Off Ver
    Office 2013
    Posts
    7

    Re: Type Mismatch Error Populating a userform

    Thank you. I hope I did it right. Rookies uh? :P

  5. #5
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,520

    Re: Type Mismatch Error Populating a userform

    This should get you in the right direction.

    Please Login or Register  to view this content.
    Thanks,
    Mike

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved.

  6. #6
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Type Mismatch Error Populating a userform

    Ok first rename your controls so that the names reflect the column that stores its data.

    So textboxes 5, 14 and 15 and checkboxes 31 and 32

    Trust me this is a powerful solution and will work for countless controls without change.

    All you need to change is the line that lists your columns ( Controls).

    Please Login or Register  to view this content.
    Last edited by mehmetcik; 03-19-2017 at 08:36 PM.

  7. #7
    Registered User
    Join Date
    03-18-2017
    Location
    Kamloops, BC Canada
    MS-Off Ver
    Office 2013
    Posts
    7

    Re: Type Mismatch Error Populating a userform

    Thanks to everybody for their assistance and input.

    mehmetcik - Your absolutely right about naming the objects. This was a sample of a much larger project. At first I thought the error was with my names and a misspelling error. That's why I started again with the original names. I wanted to eliminate any stupid errors before I started asking for help. Thank you for your assistance. Its greatly appreciated.

    BTW, I tried the code but cant seem to get it to work. I've replaced"TextBox" with the respected object names & There is the appropriate number of columns as objects. The error works but the values don't show in the textbox's

    Logit - Not exactly what I wanted but I will be needing this code in the future. Thank you so much.


    I did find an alternate solution after some studying at work. lol! Don't tell the boss.

    Please Login or Register  to view this content.
    Please let me know if this is an appropriate coding. I'm a rookie so i'm not sure.
    Last edited by Mack1981; 03-21-2017 at 01:45 PM. Reason: additional comments

  8. #8
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Type Mismatch Error Populating a userform

    I am attaching some samples for you to look at.

    The sheet "Load Controls" is the Userform that i would like you to see.
    Attached Files Attached Files
    Last edited by mehmetcik; 03-23-2017 at 08:45 PM.

  9. #9
    Registered User
    Join Date
    03-18-2017
    Location
    Kamloops, BC Canada
    MS-Off Ver
    Office 2013
    Posts
    7

    Re: Type Mismatch Error Populating a userform

    Hello hello sorry for the late response but I don't see the attachment

  10. #10
    Registered User
    Join Date
    03-18-2017
    Location
    Kamloops, BC Canada
    MS-Off Ver
    Office 2013
    Posts
    7

    Re: Type Mismatch Error Populating a userform

    Quote Originally Posted by mehmetcik View Post
    I am attaching some samples for you to look at.

    The sheet "Load Controls" is the Userform that i would like you to see.
    thank you kind sir

  11. #11
    Registered User
    Join Date
    03-18-2017
    Location
    Kamloops, BC Canada
    MS-Off Ver
    Office 2013
    Posts
    7

    Re: Type Mismatch Error Populating a userform

    Quote Originally Posted by mehmetcik View Post
    Ok first rename your controls so that the names reflect the column that stores its data.

    So textboxes 5, 14 and 15 and checkboxes 31 and 32

    Trust me this is a powerful solution and will work for countless controls without change.

    All you need to change is the line that lists your columns ( Controls).

    Please Login or Register  to view this content.
    Okay, Now I understand what you mean with naming the textbox in respect to the column name. Sir, that is straight genius. I'll work on it tomorrow.

    Just an FYI, and maybe out of the scope of this thread but....

    I did it the long way , more complicated way. and carried it forward and did the same with saving the userform changes to the worksheet.. I noticed that the calculation and changes took 8 to 10 seconds. I thought maybe my userform and worksheet were to large so the code needed time to make the changes. would this speed it up?

    either way. I'll be changing the code to reflect yours. Thanks a million.

  12. #12
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Type Mismatch Error Populating a userform

    There are other techniques that you can use to speed up excel.

    Create a new thread asking how to speed up macros and PM me the link.

    I will then post you my macro for speeding up macros.

+ 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. Run-time error ‘13’: Type mismatch on Userform textbox if empty
    By dentler in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-13-2017, 03:37 AM
  2. [SOLVED] Runtime error '13' type mismatch when posting userform entries to excel table
    By Deventre in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-28-2016, 11:32 AM
  3. Type mismatch error in userform
    By bqheng in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-11-2016, 09:29 PM
  4. Macro-created Combobox not populating; Type-Mismatch
    By Mervil in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-25-2010, 03:50 PM
  5. Type Mismatch Error Populating Label
    By ssjody in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-22-2005, 08:25 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. Passing Userform Listbox to sub causes type-mismatch error
    By Kleev in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-19-2005, 04:05 PM

Tags for this Thread

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