+ Reply to Thread
Results 1 to 12 of 12

Pre fill a form Txt box with infromation form a WS cell

  1. #1
    Forum Contributor
    Join Date
    05-01-2015
    Location
    Kent, England
    MS-Off Ver
    2013
    Posts
    148

    Pre fill a form Txt box with infromation form a WS cell

    Good morning

    I am working on a form to input 4hourly data and i need it to have three sections pre populated with the last ones focus. Can i write some code to tell the three Txt boxes to get the information from the last cell entry? then all we have to do is select the yes no button to say if they have been completed?

    This is the code i have to open the form which is where i am asuming i will have to put the code to pre fill the Txt boxes.
    Please Login or Register  to view this content.

  2. #2
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,125

    Re: Pre fill a form Txt box with infromation form a WS cell

    You'll have to store the value of the controls somewhere before closing the userform; to a sheet, to a text file, or to the built-in property fields, such as Author, subject, etc.

    Then when you reopen the form, reset the values to the controls.
    David
    (*) Reputation points appreciated.

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

    Re: Pre fill a form Txt box with infromation form a WS cell

    Put the code in the userform's Initialize event.

    You don't say where the data will come from so here's a simple example that fills three textboxes with the last values from columns A, B and C on Sheet1.
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  4. #4
    Forum Contributor
    Join Date
    05-01-2015
    Location
    Kent, England
    MS-Off Ver
    2013
    Posts
    148

    Re: Pre fill a form Txt box with infromation form a WS cell

    Ok sorry some more information.

    The 3 texted boxes are named Txt_LastFocus1, Txt_LastFocus2 and Txt_LastFocus3 the data is located in "Data" sheet columns R,T and V

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

    Re: Pre fill a form Txt box with infromation form a WS cell

    Try this.
    Please Login or Register  to view this content.

  6. #6
    Forum Contributor
    Join Date
    05-01-2015
    Location
    Kent, England
    MS-Off Ver
    2013
    Posts
    148

    Re: Pre fill a form Txt box with infromation form a WS cell

    Quote Originally Posted by Norie View Post
    Try this.
    Please Login or Register  to view this content.


    I get an error saying invalid use of Me Keyword

  7. #7
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,908

    Re: Pre fill a form Txt box with infromation form a WS cell

    Did you put the code in the userform module ?

    This also works.

    Please Login or Register  to view this content.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  8. #8
    Forum Contributor
    Join Date
    05-01-2015
    Location
    Kent, England
    MS-Off Ver
    2013
    Posts
    148

    Re: Pre fill a form Txt box with infromation form a WS cell

    Quote Originally Posted by bakerman2 View Post
    Did you put the code in the userform module ?

    This also works.

    Please Login or Register  to view this content.
    Where is the userform module i put it in the open form module

  9. #9
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: Pre fill a form Txt box with infromation form a WS cell

    Have a read, it's something you're going to have to understand.

  10. #10
    Forum Contributor
    Join Date
    05-01-2015
    Location
    Kent, England
    MS-Off Ver
    2013
    Posts
    148

    Re: Pre fill a form Txt box with infromation form a WS cell

    Thanks for the help i will read up now. its a step learning curve

  11. #11
    Forum Contributor
    Join Date
    05-01-2015
    Location
    Kent, England
    MS-Off Ver
    2013
    Posts
    148

    Re: Pre fill a form Txt box with infromation form a WS cell

    i have uploaded a copy of my WB as i am now getting an error code. I have put the code to populate the Focus in the Form but i am now getting an error when i try to open the form using the button on Sheet 1 (Data)
    Attached Files Attached Files

  12. #12
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: Pre fill a form Txt box with infromation form a WS cell

    Please Login or Register  to view this content.
    You don't have a worksheet with the Tab name 'Sheet1'.

    The syntax
    Please Login or Register  to view this content.
    is referring to a sheet Tab name. As this can easily be changed by the user it's not considered 'good code' - as soon as the tab is renamed the code will error.

    Much safer to refer to worksheets using the Code Name as this can only be changed in the VBA dev environment - you should change the code to
    Please Login or Register  to view this content.
    You now need to add this to your reading list. In fact, a general browse around that site would probably be the best thing you do today (Code wise), starting with this to really get off to a flying start with VBA
    Last edited by cytop; 06-18-2017 at 08:33 AM.

+ 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. Replies: 9
    Last Post: 09-16-2015, 08:45 PM
  2. Auto fill a cell from user form
    By markday in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-24-2015, 05:47 PM
  3. Filling form fields via worksheet dropdowns, user update via form, change form color
    By Demosthenes&Locke in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-11-2010, 08:58 AM
  4. Auto Fill Web Form using Excel User Form
    By vandanavai in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-09-2008, 02:26 AM
  5. Replies: 0
    Last Post: 06-05-2006, 02:45 AM
  6. how to get a data form to fill you own exel sheet (was data-form
    By erik van buijtenen in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 05-30-2006, 12:35 PM
  7. [SOLVED] make a cell required to fill-in on form template
    By Jo in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 12-01-2005, 03:10 PM

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