+ Reply to Thread
Results 1 to 21 of 21

Link a txtbox value to a specific record?

  1. #1
    Forum Contributor
    Join Date
    08-17-2009
    Location
    West Midlands
    MS-Off Ver
    Excel 2016
    Posts
    213

    Link a txtbox value to a specific record?

    Greetings experts,

    Apologies if this question has already been answered, but my searches haven't yielded anything - although I probably didn't express myself very well and I am very new to VBA!

    Basically, I have a large spreadsheet with basic data including names, dates and a unique identifier number (UIN). I have created a questionnaire in a userform (with a UIN txtbox) and want to link the answers to the specific individuals on the worksheet.

    i.e. If UIN 201 fills in the questionnaire on the userform it will enter the details on the spreadsheet next to the details already entered for UIN 201.

    This is probably a really simple action and I'm making a big meal out of it!

    Any help would be gratefully appreciated.

    Thanks

    Steve
    Last edited by SAsplin; 08-28-2009 at 11:30 AM.

  2. #2
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Link a txtbox value to a specific record?

    It might help to attach a sample workbook, but it sounds as if you could use some sort of lookup formula, e.g. VLOOKUP(textbox value, UIN data, column)

  3. #3
    Forum Contributor
    Join Date
    08-17-2009
    Location
    West Midlands
    MS-Off Ver
    Excel 2016
    Posts
    213

    Re: Link a txtbox value to a specific record?

    I have attached an example of the spreadsheet I am using.

    I would like to use the questions entered on the userform to populate columns G through J for the specific person filling in the form.

    Hope this makes things a bit clearer.

    Steve
    Attached Files Attached Files

  4. #4
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Link a txtbox value to a specific record?

    There doesn't appear to be a userform in your attachment?

  5. #5
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Link a txtbox value to a specific record?

    Her's a quick example based on your data
    Attached Files Attached Files
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  6. #6
    Forum Contributor
    Join Date
    08-17-2009
    Location
    West Midlands
    MS-Off Ver
    Excel 2016
    Posts
    213

    Re: Link a txtbox value to a specific record?

    Roy -I tried your example but it came up with:

    Compile error:

    Method or data member not found.

    I've attached the sample spreadsheet again with a simple userform. I'd like any data entered in the question txtboxes to appear on the spreadsheet beside the relevant UIN number entry (rows G trough J).

    Thanks,

    Steve
    Attached Files Attached Files

  7. #7
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Link a txtbox value to a specific record?

    That's strange it works fine for me. What are you expecting in your textboxes?

  8. #8
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Link a txtbox value to a specific record?

    Add a command button and assign this code to it:
    Please Login or Register  to view this content.

  9. #9
    Forum Contributor
    Join Date
    08-17-2009
    Location
    West Midlands
    MS-Off Ver
    Excel 2016
    Posts
    213

    Re: Link a txtbox value to a specific record?

    Strange - it runs ok now. However, I didn't want it to pull data from the sheet when you enter the UIN.

    The data entered in to the text boxes (just text) would be completely new and would need to be added on to the end of the data for e.g. UIN 201 (row G onwards).

  10. #10
    Forum Contributor
    Join Date
    08-17-2009
    Location
    West Midlands
    MS-Off Ver
    Excel 2016
    Posts
    213

    Re: Link a txtbox value to a specific record?

    Thanks StephenR - that seems to work. If there were a number of sheets, where in the code would I specify which sheet to add the data to?

  11. #11
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Link a txtbox value to a specific record?

    Quote Originally Posted by SAsplin View Post
    Strange - it runs ok now. However, I didn't want it to pull data from the sheet when you enter the UIN.

    The data entered in to the text boxes (just text) would be completely new and would need to be added on to the end of the data for e.g. UIN 201 (row G onwards).
    That wasn't clear in your post.

    I wouldn't rely on a textbox for entering the UIN, better to limit the user options to avoid errors, hence a combobox.

    Remove the combobox coding, then add a button and place this code in the button's click event
    Please Login or Register  to view this content.

  12. #12
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Link a txtbox value to a specific record?

    See the With line.
    Please Login or Register  to view this content.

  13. #13
    Forum Contributor
    Join Date
    08-17-2009
    Location
    West Midlands
    MS-Off Ver
    Excel 2016
    Posts
    213

    Re: Link a txtbox value to a specific record?

    Thanks guys, you've been really helpful (as always!). Think I've got it sorted now.

    Thanks again,

    Steve

  14. #14
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Link a txtbox value to a specific record?

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save

  15. #15
    Forum Contributor
    Join Date
    08-17-2009
    Location
    West Midlands
    MS-Off Ver
    Excel 2016
    Posts
    213

    Re: Link a txtbox value to a specific record?

    Sorry!! Still having troubles. The solution Stephen gave works fine with UIN's that are purely numerical, but some have a letter in eg. A201.

    The code string doesn't seem to like this!

  16. #16
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Link a txtbox value to a specific record?

    A bit clunky but seems to work. You would be better off with Roy's suggestion of a combo box though.
    Please Login or Register  to view this content.

  17. #17
    Forum Contributor
    Join Date
    08-17-2009
    Location
    West Midlands
    MS-Off Ver
    Excel 2016
    Posts
    213

    Re: Link a txtbox value to a specific record?

    Sorry to be a pain, but I'm still having some niggly problems with this. I agree that a combo box would be more useful, but there are over 3000 entries on the spreadsheet - which would be a mammoth task to add to a combo box - especially as more are added each day.

    Another problem would seem to be the length of some UIN's we have - some are thirteen digits long e.g. B654389234901 which I believe is too long for Clng?

  18. #18
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Link a txtbox value to a specific record?

    maybe use CStr & the Find function

  19. #19
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Link a txtbox value to a specific record?

    Are you asking or telling? If it's text it doesn't need converting. If not, there are probably other approaches.

    EDIT: picking up on Roy's suggestion:
    Please Login or Register  to view this content.
    Last edited by StephenR; 08-28-2009 at 11:17 AM.

  20. #20
    Forum Contributor
    Join Date
    08-17-2009
    Location
    West Midlands
    MS-Off Ver
    Excel 2016
    Posts
    213

    Re: Link a txtbox value to a specific record?

    I believe a figure such as B654389234901 is too long for CLng to handle. This type of number forms some of our UIN's. When this type of UIN is entered in to the above solutions it always reports an error.

  21. #21
    Forum Contributor
    Join Date
    08-17-2009
    Location
    West Midlands
    MS-Off Ver
    Excel 2016
    Posts
    213

    Re: Link a txtbox value to a specific record?

    Wow! You guys are fantastic. Apologies for the numerous problems with this and thank you so much for your solutions. I'm now more than happy to mark this one up as 'Solved!'

    Steve

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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