0
votes

I have a form of venues for an events company database. In this form there is a subform of venue types which could include hotel, bar, restaurant etc

I would like to use VBA code to have the form display certain fields and tab pages depending on what's in this subform

E.g. If it was a textbox, I could say: If [VenueTypes subform].VenType = "Hotel" then PageHotel.Visible = true

What is the equivalent of this to search a subform?

Many many thanks!

1

1 Answers

0
votes

I think you don't want to search the subform, but to access one control on it. Search for data should always be done by a query, because a form doesn't store data, it just presents it.

From the "code behind form" you can access a control on a subform by

Me.subFormControl.Form.controlOnSubform.Value

"subFormControl" is the name of the subform object (not the form being used to populate the subform).

"controlOnSubform" is the name of the control on the subform.

Whenever the subform's data is changing, this can be recognized by the subform's "OnCurrent" event. The code for this event should tell the main form to update its content:

Me.Parent.nameOfThePublicSubInParentForm