Share via

need help with using a subform from a button

Anonymous
2022-11-17T01:16:25+00:00

Im calling a subform with a button and have linked the id key from the main form to the child form. it displays the existing data correctly. but doesnt fill in the main forms id in the child record when entering a new child record. what am i missing?

Microsoft 365 and Office | Access | For home | Other

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

6 answers

Sort by: Most helpful
  1. Anonymous
    2022-11-17T13:58:08+00:00

    You might like to take a look at FormsDemo.zip in my public databases folder at:

    https://onedrive.live.com/?cid=44CC60D7FEA42912&id=44CC60D7FEA42912!169

    If you have trouble downloading a specific file, clicking on the 'Download' button at the top of the page while no files are selected should download a zip file of all files in the folder, from which you should then be able to unpack the relevant file.

    This little demo file illustrates, amongst other things, the use of 'linked' forms in both dialogue and synchronized mode.  In the demo the primary key of the 'parent' form's recordset is passed to the 'linked' form as the OpenArgs property of the OpenForm method, and then assigned to the DefaultValue property of the relevant control in the 'linked' form, using the following code in the 'linked' form's Open Event procedure:

    Private Sub Form_Open(Cancel As Integer)

        If Not IsNull(Me.OpenArgs) Then

            Me.Event.SetFocus

            Me.cboClient.DefaultValue = """" & Me.OpenArgs & """"

       End If

    End Sub

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2022-11-17T05:14:19+00:00

    thank you, i will try that. I didnt put the second form on the main form because it was too big.

    Was this answer helpful?

    0 comments No comments
  3. Duane Hookom 26,825 Reputation points Volunteer Moderator
    2022-11-17T04:54:19+00:00

    Is there a reason you didn't simply add the form as a subform? This would automate the inheritance of the FamilyID. Otherwise you can use the OpenArgs of the DoCmd.OpenForm method sending the FamilyID as the OpenArg. In the Adults form you would need to check for the existence of the OpenArg and if found, use the value to set the default value for the FamilyID in the Adults form.

    You will find lots of examples if you search the web for "ms access openargs"

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2022-11-17T01:58:29+00:00

    you are right. its just another form. and i have set thekey fields. FamilyID in the Family form = FamilyID in the Adults form. It displays existing records fine, but the FamilyID field for a new Adult record is blank.

    Was this answer helpful?

    0 comments No comments
  5. Duane Hookom 26,825 Reputation points Volunteer Moderator
    2022-11-17T01:34:12+00:00

    I'm not sure how you are "calling a subform" since a subform is actually a control on the main form and opens when the main form opens. If you are opening a separate form, you will need to pass the main form ID value to the newly opened form and set the default value of the child record ID.

    Was this answer helpful?

    0 comments No comments