Working with Subforms

 < Day Day Up > 

Subforms are a peculiar sort of control: they contain an entire form. This form, of course, can contain its own controls, including other subforms (although you can't go deeper than sub-subforms in Access).

To work with subforms, you must first know how to refer to the controls that they contain. The general form of control reference for subforms is as follows:

 

 Forms![top-levelformname].[subformcontrolname].Form![controlname] 

For example, the Projects form in the TimeTrack database contains a subform control named Tasks. To display the value of the TaskName field in the current row in this subform, you can type this expression into the Immediate window:

 

 ?Forms!Projects.Tasks.Form!TaskName 

Of course, if you're working in code behind the Projects form, you can shorten this reference by using the Me shortcut, perhaps assigning the result to a variable:

 

 varTaskName = Me.Tasks.Form!TaskName 

After you understand how to refer to subform controls, working with subforms is exactly like working with forms. The key is the .Form property. This property lets you "look inside" the subform to refer to the controls that it contains.

     < Day Day Up > 


    Automating Microsoft Access with VBA
    Automating Microsoft Access with VBA
    ISBN: 0789732440
    EAN: 2147483647
    Year: 2003
    Pages: 186

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net