Share via

Access Subform conditional on form field value

Anonymous
2017-04-17T17:06:10+00:00

I have four tables:

Customers

DetailsA

DetailsB

DetailsC 

Customers has a number, a name, and a detail value like A, B, or C

In my customers form, i want to conditionally show different details forms based on the valued of A, B, or C, since each details form offers different field choices. I tried this vba on the load and selection change event but the link isn't working, ideas on what i did wrong? TIA

Private Sub Form_Load()

Select Case Trim(ModelName.Value)

    Case "A"

        frmModelADetails.Visible = True

        frmModelBDetails.Visible = False

        frmModelCDetails.Visible = False

    Case "B"

        frmModelADetails.Visible = False

        frmModelBDetails.Visible = True

        frmModelCDetails.Visible = False

    Case "C"

        frmModelADetails.Visible = False

        frmModelBDetails.Visible = False

        frmModelCDetails.Visible = True

End Select

End Sub

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

1 answer

Sort by: Most helpful
  1. Anonymous
    2017-04-17T17:38:34+00:00

    When you say "the link isn't working", what do you mean?

    I assume that "frmModelADetails", "frmModelBDetails", and "frmModelCDetails" are the names of the subform controls on your main form.  I would expect you to need to apply the code to choose which form to show in the form's Current event, so if the only problem is that navigating the main form from customer to customer doesn't switch the visible subform, then try moving the code to the Current event instead of the Load event.

    Was this answer helpful?

    0 comments No comments