Results 1 to 8 of 8
  1. #1
    winter is offline Novice
    Windows XP Access 2003
    Join Date
    Jul 2009
    Posts
    6

    Self-populating one form from another

    Hi, I have a large questionnaire that requires the users to enter data from each participant in several forms. I've included command buttons that will allow the user to close the current form and open the next form. There are separate tables for each of these forms, which are linked by the ID field, which is also the key. I would like to minimize entry error by having the ID control of forms 2-8 self-populate based on what the user entered in form 1. The field is masked for input as LL000;. Is there a way to have the controls self-populate from form 1? Thanks!

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    How about having Form1 save the ID in a Global Variable and then have each form retrieve it in the OnLoad event? You could also just pass this data to the next form in the OpenArgs argument of the OpenForm command.

  3. #3
    winter is offline Novice
    Windows XP Access 2003
    Join Date
    Jul 2009
    Posts
    6
    Thanks RG, those sound like great approaches. I'm still having some trouble getting the OpenArgs to work. I've found lots of examples that show how to send multiple variables, but not so much just the one. This is what I have in the code for the first form, which is called frmFB001:

    Private Sub cmdFB001_Click()
    If Me.Dirty Then Me.Dirty = False
    DoCmd.OpenForm "frmFB212a", OpenArgs:="ID001"
    DoCmd.Close acForm, "frmFB001"
    End Sub

    I want whatever was entered in ID001 on frmFB001 to be sent to ID212a on frmFB212a. Should the two ID controls have the same name so it knows where to send the value?

    The dirty property is there so it will make sure that required fields have been entered before closing the form and opening frmFB212a. The ID control is called ctr001. Because it's not a string, do I need to anything else? Thanks again for all your help!

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Assuming ID001 is a control on your form then you want:

    DoCmd.OpenForm "frmFB212a", OpenArgs:= Me.ID001
    DoCmd.Close acForm, Me.name, acSaveNo

    ...and in the OnLoad event of the frmFB212a form you want:
    Code:
    If Not IsNull(Me.OpenArgs) Then
       Me.ID212a = OpenArgs
    End If

  5. #5
    winter is offline Novice
    Windows XP Access 2003
    Join Date
    Jul 2009
    Posts
    6
    So I've added the following to the code for form frmFB001:

    DoCmd.OpenForm "frmFB212a", OpenArgs:= Me.ID001
    DoCmd.Close acForm, Me.name, acSaveNo

    And the I put this in the code for form frmFB212a:

    Private Sub OnLoad()
    If Not IsNull(Me.OpenArgs) Then
    Me.ID212a = OpenArgs
    End If
    End Sub

    I noticed that in the properties window, nothing is showing next to OnLoad. Also, when I compile the database I get the following error:

    Member already exists in an object module from which this object module derives.

    Any ideas? Thanks again!

  6. #6
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Did you press the "..." button next to the OnLoad event? Don't duplicate the Sub...End Sub lines.

  7. #7
    winter is offline Novice
    Windows XP Access 2003
    Join Date
    Jul 2009
    Posts
    6
    It works!!

    Thank you SO much for your help, I hope you had a great weekend!

  8. #8
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Glad I could help.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 4
    Last Post: 06-10-2009, 12:43 PM
  2. Populating other fields from combo box.
    By nkenney in forum Forms
    Replies: 1
    Last Post: 05-14-2009, 10:39 PM
  3. Populating Data in forms
    By cjbeck71081 in forum Forms
    Replies: 4
    Last Post: 01-16-2007, 04:15 PM
  4. Calculated Text Box Populating in Table
    By Debbie in forum Access
    Replies: 2
    Last Post: 11-13-2006, 08:02 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums