Same Public Procedure for Forms AND SubForms

dungstar

Registered User.
Local time
Today, 01:41
Joined
Mar 13, 2002
Messages
72
I have several forms which contain a set of controls I need to manipulate in VBA. The set of controls are located on the main form (forms that do not have a subform), and on the subform of another form (2 other forms actually).

I need to create a public procedure that will modify the controls' properties based on which forms are being used. Is there a way to create a single common public procedure that will accommodate both the main form and the subforms?

Example code if it were run independently in different procedures:

Forms!frmMainNoSfrm.cmdControl.Enabled = False

Forms!frmMainWithSfrm
.frmSubform.Form.cmdControl.Enabled = False

Thanks!
 
Check out 'Property Procedures' in the MS Access help (this forum clued me into them). Maybe that is what you're getting at?
 
You could create a sub/function that requires a variable to be passed to it. Pass it a Form, and reference the form in the procedure. Example:

Public Sub Enable_Buttons(MyForm as Form)
MyForm.cmdControl.Enabled = False
End Sub

You reference the code by:

Private Sub Form_Open()
Enable_Buttons(Forms.frmMainNoSfrm)
OR
Enable_Buttons(Forms.frmMainWithSfrm.frmSubform.Form)
End Sub

Post if you have any questions.
 

Users who are viewing this thread

Back
Top Bottom