Home  Fees/Services  Microsoft Access Templates  Tutorials  Access Download  Articles  Search  Contact  Privacy  Links

Access VBA Tutorial
   
Access Programming Examples & Code Samples

Referring to Subforms in VBA Visual Basic Tutorials, Workarounds & Solutions for VB6
Access Forms & Subform Reference Methods




VBA Tutorials:
Access to Google Earth
VB6 Age Calculation
Change Case VBA
VBA Email via Gmail
VBA Outlook Email
Read Email Access
RTF Report Email
Send Outlook Email Access
Calculate Running Sum
Concatenate Records
VBA Stock Quotes
VBA CreateQueryDef
Database Path Solution
Detail-Master Update
Field Validation VBA
Field Value New-Old
FindFirst Recordset
Get Version Number
VB6 Global Parameters
VBA Global Variables
Labels as Links
List Box Files List
VBA Mail Merge
OutputTo Crosstab
Sort Recordset Trick
VBA Recordset Filters
Reference Form Field
VBA Select Case
Transaction Processing

Visual Basic Function Examples


Reference Nested Form Fields in VBA

Reference Microsoft Access Form Controls from VB Script

Have you come across the maddening task of trying to reference a deeply nested form, form field or control?

Here is a real example of a deeply nested subform control - a combo box control which we want to disable.

Forms![MainMenu]![F_Project_Results].Form![F_Test_Results].
Form![F_Test_Materials].Form![F_Test_Results_Dates]
.Form![F_Test_Result_Parameters]
.Form![Parameter_Combo].Enabled = False

Isn't there an easier way to reference these fields directly?  The answer is YES!

You can reference any form directly using it's reference in visual basic:

Form_F_Test_Result_Parameters.Parameter_Combo.Enabled = False

Notice that we prefix the form name with Form_ use the dot '.' operator to reference the form control.

There is one trick to this referencing method - the form which you are referencing must have it's Has Module property set to Yes.

This method only seems to work in VBA code.  Doesn't work when referencing a form field as a query parameter nor in any of the property settings.

Note that you can also reference a form's functions and subroutines using the same method.  For example:

Form_F_Test_Result_Parameters.Requery
(requeries the form)

Call Form_F_Test_Result_Parameters.Find_Test_Combo_AfterUpdate
(note that the function or subroutine must be Public and not Private to reference it from another form or VBA module.)

And requery a combo box after its row source updates:

Form_F_Test_Materials.Find_Material_Combo.Requery








Have errors?  No doubt we can answer your question quickly and easily.  Simple questions get simple answers at no charge via email.




Popular Database Templates:

PM/Preventive Maintenance Access Template

Work Order Software

Real Estate Marketing Template Database




Contact Information

VBA runtime tips tricks fix solution

Access Visual Basic/VBA/VBScript/VB6 Tutorials
Visual Basic Error Fix & Problem Solutions