简体   繁体   中英

MS Access: How to reference subform of navigation form?

I have a navigation form something like this:

在此处输入图片说明

There is a command button in the Customers form that I would like to call a public sub from the Orders form, but I can't figure out how to reference it. I have tried:

Forms!frmOrders.MyPublicSub("Arg")

but I got the error "cannot find the referenced form 'frmOrders'. Does anyone know how to do this properly?

Thank you.

If you have a VBA procedure ( Sub or Function ) that has been declared in the Class Module for an Access object (Form or Report) then you should expect it to behave as Private to that object. If you want a procedure that can be called from "other places" then put it in a regular VBA Module (and declare it as Public , just to be sure).

While what Gord Thompson above said is true... there are times when it is easier to make reference to a procedure within the form directly... for example if your procedure is referencing several controls within the sub form itself. In cases like these you can reference the Navigation Sub Form by calling it like so:

Me.NavigationSubform.Form.YourPublicProcedure

But be careful... there are a few gotcha's with Navigation Forms... (as we have all discovered). You obviously have experience in referencing sub forms in a normal Parent Form/ Sub Form relationship as in your code above... but navigation forms are different in how they work and are handled. The code I submitted above will reference your sub forms public sub... but if you are not currently viewing the sub form that has the public sub you will throw an exception.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM