+ Reply to Thread
Results 1 to 6 of 6

Re-populate User Form from the database record

Hybrid View

  1. #1
    Registered User
    Join Date
    07-24-2013
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    73

    Re-populate User Form from the database record

    My Excel document takes the form of a datasheet lines of entry, populated by a Userform, which transfers the data across to a new row

    The complication is that each entry will change in some regards later down the line, and information needs to be updated.

    Ideally, the practitioner should be able to edit the record in the user form, rather than the spreadsheet.

    Therefore, is there any code which, for example clicking in a row, re-populates the User form so that the data can be amended and then put back into the row as a replacement?
    I suppose for example this could take the form of an event handler upon double clicking in a persons record, or a command button from which you select the appropriate record from a 'Go to' interface.

    Thanks in advance for any assistance.
    Henry Bukowski

    linked Post: http://www.mrexcel.com/forum/excel-q...ml#post4099094

  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: Re-populate User Form from the database record

    Are the users inputting data into the form once per day or is it several times per day? If once per day, you could create a "Submit" button on the form. This would transfer the data and keep the form open.
    If they input the data several times a day, can you create a button on the spreadsheet and assign a macro for "Show UserForm", that they can click on when they need to?
    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
    Registered User
    Join Date
    07-24-2013
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    73

    Re: Re-populate User Form from the database record

    Quote Originally Posted by gmr4evr1 View Post
    Are the users inputting data into the form once per day or is it several times per day? If once per day, you could create a "Submit" button on the form. This would transfer the data and keep the form open.
    If they input the data several times a day, can you create a button on the spreadsheet and assign a macro for "Show UserForm", that they can click on when they need to?
    Thanks - so actually this data will be updated less frequently, so keeping the form open might not be suitable.
    It might be every couple of days when new information is gathered regarding the client which needs updating.

    Cheers

  4. #4
    Valued Forum Contributor john55's Avatar
    Join Date
    10-23-2010
    Location
    Europe
    MS-Off Ver
    Excel for Microsoft 365
    Posts
    2,060

    Re: Re-populate User Form from the database record

    maybe this, just try
    Option Explicit
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    'click in any cell from a2 to a200 and the userform is populated...
    If Target.Count > 1 Then Exit Sub
    If Intersect(Target, Range("A2:A200")) Is Nothing Then Exit Sub
    UserForm1.Show
    End Sub
    
    
    Private Sub UserForm_Initialize()
    'read the data from active row
        With Me
            .TextBox1.Value = Cells(ActiveCell.Row, "A").Value
            .TextBox2.Value = Cells(ActiveCell.Row, "B").Value
    'more textboxes
    '
    '
        End With
    End Sub
    
    the button for transfering yr dada
    Private Sub CommandButton1_Click()
    
             Cells(ActiveCell.Row, "A").Value = TextBox1.Value
             Cells(ActiveCell.Row, "B").Value = TextBox2.Value
       
    End Sub
    Regards, John55
    If you have issues with Code I've provided, I appreciate your feedback.
    In the event Code provided resolves your issue, please mark your Thread as SOLVED.
    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

    ...enjoy -funny parrots-

  5. #5
    Registered User
    Join Date
    07-24-2013
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    73

    Re: Re-populate User Form from the database record

    Quote Originally Posted by john55 View Post
    maybe this, just try
    Option Explicit
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    'click in any cell from a2 to a200 and the userform is populated...
    If Target.Count > 1 Then Exit Sub
    If Intersect(Target, Range("A2:A200")) Is Nothing Then Exit Sub
    UserForm1.Show
    End Sub
    
    
    Private Sub UserForm_Initialize()
    'read the data from active row
        With Me
            .TextBox1.Value = Cells(ActiveCell.Row, "A").Value
            .TextBox2.Value = Cells(ActiveCell.Row, "B").Value
    'more textboxes
    '
    '
        End With
    End Sub
    
    the button for transfering yr dada
    Private Sub CommandButton1_Click()
    
             Cells(ActiveCell.Row, "A").Value = TextBox1.Value
             Cells(ActiveCell.Row, "B").Value = TextBox2.Value
       
    End Sub
    Thanks John.
    So bear with me here - the code you posted sucessfully brings up the UserForm...but what it doesn't yet seem to do is 'take up' the values of the row in question.

    I have amended the particular routine so that the text box names match my own:

    Private Sub UserForm_Initialize()
    'read the data from active row
        With Me
            .cboDATE.Value = Cells(ActiveCell.Row, "A").Value
            .cboREF.Value = Cells(ActiveCell.Row, "C").Value
            .cboCI.Value = Cells(ActiveCell.Row, "D").Value
            .age.Value = Cells(ActiveCell.Row, "E").Value
            .ComboBox25.Value = Cells(ActiveCell.Row, "F").Value
            .cboGEN.Value = Cells(ActiveCell.Row, "G").Value
    'more textboxes
    '
    '
        End With
    End Sub
    Thanks!

  6. #6
    Valued Forum Contributor john55's Avatar
    Join Date
    10-23-2010
    Location
    Europe
    MS-Off Ver
    Excel for Microsoft 365
    Posts
    2,060

    Re: Re-populate User Form from the database record

    Hi Henry,
    I uploaded a test file just to see how it works, please try to see each piece of code.

    cheers!
    Attached Files Attached Files

+ 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. Calling a user form initialize sub when entering the form to populate combobox...
    By regupnorth in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-02-2012, 07:24 AM
  2. Display user's database or record after login
    By stoey in forum Access Programming / VBA / Macros
    Replies: 8
    Last Post: 09-12-2011, 11:58 AM
  3. Add next record using user form
    By rajeev.raj in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-26-2010, 02:15 AM
  4. Amend a record in a database with a form.
    By Jwalker in forum Excel General
    Replies: 0
    Last Post: 09-23-2006, 05:16 PM
  5. [SOLVED] Insert record into Excel database using a custom VBA form?
    By dspame@yahoo.com in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-30-2005, 11: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