Referencing a subform from a different form

karatelung

Registered User.
Local time
Today, 08:58
Joined
Apr 5, 2001
Messages
84
I've done a search and was unable to find exactly what I need.

I have a combo box, PerDiem, that has a list of rates that come from a table, tblPerDiemList. I have a button that opens a form, frmPerDiemRates, where you can add a rate to the list.

I want to requery the combo box. The following code works when I open the subform separately as it's own form:

(OnClose event)

DoCmd.Close
Forms![subfrmPlacement]!PerDiem.Requery

When I open the main form containing the subform, subfrmPlacement, and then open the frmPerDiem, the Requery part doesn't work because it's not referencing the subform correctly.

How can I make this work? Please help.

Thanks,

Richard
 
Try syntax like this: Forms!subfrmPlacement.Form!PerDiem.Requery
 
that didn't work. i get a message saying that it can't find the form. i think in the statement you have to include the main form and subform, but i can't remember exactly how.

thanks.
 
Sorry, you're right. Try something with this syntax:
Forms("mainform").Controls("subfrmPlacement").Form.Controls("PerDiem").Requery

This can be simplified in some cases, depending (I think) on which version of Access you are using. control collection is the default collection for Forms objects, and the Form object is the default collection for subForms.

I find it easier and better to use the (" ") type notation rather than bang "!" notation for referring to objects within a collection. From what I've read, Access just translates bang notation into the (" ")- type notation in the background anyway.
 

Users who are viewing this thread

Back
Top Bottom