Referencing Subforms

N

NEWER USER

I have a subform on a form and when Double clicking on a field in the
subform, another form
opens and displays the same number on the newly opened form as the subform.
Code on subform as follows:

Private Sub Number_DblClick(Cancel As Integer)
On Error GoTo Number_DblClick_Err
Dim strDoc As String
strDoc = "frmProductSync"
'Synchronize Number field; frmOrderEntryList to frmProductSync
DoCmd.OpenForm strDoc, acNormal, "",
"Number=Forms!frmOrderEntry!fsubOrderEntryList.Form!Number", , acNormal
DoCmd.GoToControl "Number"

Number_DblClick_Exit:
Exit Sub

Number_DblClick_Err:
MsgBox Err.Description
Resume Number_DblClick_Exit

End Sub

This works very well.

I would like to place this subform on several other forms and still have the
ability to open the linked form and display same number as number on
subform. How might I re-work
my code in referencing the main form so I don't have to create several exact
subforms (named differently) when changing the main form reference. Example:

"Number=Forms!frmOrderEntry!fsubOrderEntryList.Form!Number", , acNormal

"Number=Forms!frmGross Profit!fsubOrderEntryList1.Form!Number", , acNormal

"Number=Forms!frmInterchange!fsubOrderEntryList2.Form!Number", , acNormal

I have tried "Number=Me!fsubOrderEntryList.Form!Number thinking "Me" would
reference my Main forms allowing me to use one subform on all forms. No such
luck. I get the Enter Parameter error.

Any help appreciated.

Thanks
 
J

Jeanette Cunningham

You should be able to do it with this

"Number=Me!Number"

The above assumes that the double click happens on the subform and that
'Number' is a control or field on the subform.

If however you are double clicking on the parent form, the where clause
changes to

"Number=Me.fsubOrderEntryList.Form.Number"


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top