Dynamic Subform

jalverson

Registered User.
Local time
Today, 15:39
Joined
Oct 27, 2004
Messages
42
I have a main form that displays different part numbers and the corresponding material type for each item. For example,

Part 1 metal
part 2 candy
part 3 label

I have created specific subforms based on the type of the material. I want to place a command button on each record, and when the button is clicked, the correct subform based on the material code will open. For example, the above 3 items are displayed on the form, if the user clicks the button next to candy, then the candy subform opens and if the user clicks the button next to label, then the label subform opens.

Thanks for helping solve my question.

Jeff
 
Hi jalverson,

Not sure what your button names are or your subforms but I have used the wizard in order to create the code based on a subform with name frmMetal_subform (shown in code below in green) and a command button with name CmdOpenMetalsubform (shown in code below in red).

So in order to make others just change the red and green in the code below according to the names that you are using on the CLICK property of each button.


Code:
Private Sub [COLOR="Red"]CmdOpenMetalsubform[/COLOR]_Click()
On Error GoTo Err_[COLOR="Red"]CmdOpenMetalsubform[/COLOR]_Click

    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "[COLOR="SeaGreen"]frmMetal_subform[/COLOR]"
    DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_[COLOR="Red"]CmdOpenMetalsubform[/COLOR]_Click:
    Exit Sub

Err_[COLOR="Red"]CmdOpenMetalsubform[/COLOR]_Click:
    MsgBox Err.Description
    Resume Exit_[COLOR="Red"]CmdOpenMetalsubform[/COLOR]_Click
    
End Sub

Good Luck with it.

I hope it helps.:p

Robert88
 
Last edited:

Users who are viewing this thread

Back
Top Bottom