Share via

Subform Button to Open another Subform

Anonymous
2015-10-28T20:13:47+00:00

Hello,

I have a button embedded in a subform to open up a modal window. This works well if I just open the subform and click the button. It opens to the correct record to display. However when I have the main form open with the embedded subform it displays a #NAME error in the control record field.

I'm not sure how to link through each form to get the control to work.

Currently the macro language is:

Form Name: Sample_Form

View: Form

Filter Name: 

Where Condition = ="[Serial Number]=" & "'" & [Serial Number] & "'"

Data Mode:

Window Mode:

The control source for the control record is

=[Forms]![Sample_Table_Subform]![Serial Number]

Thanks for any assistance :)

Microsoft 365 and Office | Access | For home | Windows

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

Answer accepted by question author

Anonymous
2015-10-28T20:54:31+00:00

Because you are trying to reference a sub form when you open your other form, the system does not recognize "[Forms]![Sample_Table_Subform]![Serial Number]."  To reference a field or control on a sub form, you need to use the syntax: Forms![Parent Form Name]![Sub Form Control Name].Form![Serial Number].

However, because your button is located in the sub form, you need only do the following using VBA instead of a Macro:

Private Sub YourCommandButtonName_Click()

    If (Not IsNull(Me.[Serial Number])) Then

        DoCmd.OpenForm "Sample_Form", , , "[Serial Number]='" & Me.[Serial Number] & "'"

    End If

End Sub

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

6 additional answers

Sort by: Most helpful
  1. Anonymous
    2015-10-28T21:04:19+00:00

    Thanks for the assistance again! I was sure that it had to be something like that but couldn't find a reference in my searching.

    Thanks!

    Was this answer helpful?

    0 comments No comments
  2. ScottGem 68,830 Reputation points Volunteer Moderator
    2015-10-28T20:53:35+00:00

    And what is the name of the subform control?

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2015-10-28T20:45:59+00:00

    Yes the button is on the embedded subform, I moved some information off of the subform to the subsub form and hid it with a button. 

    User_Information is the main form with the primary key being [User_Information]![User_ID] each user has x serial numbers assigned to them which are displayed in the subform with relative information and is designed to navigate only to serial numbers assigned to that User.

    Was this answer helpful?

    0 comments No comments
  4. ScottGem 68,830 Reputation points Volunteer Moderator
    2015-10-28T20:30:21+00:00

    Is this button on the embedded subform? Is Serial Number a control on the subform? what is the name of the main form and the name of the subform control?

    Was this answer helpful?

    0 comments No comments