Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Different Method to reference a subform 1

Status
Not open for further replies.

perrymans

IS-IT--Management
Nov 27, 2001
1,340
US
I have the following code from a database that is using a reference to a form with Forms():

Code:
    CurrentDb.Execute " INSERT INTO tblFilesFound" & _
                               " (" & _
                                  " FilePath," & _
                                  " FileName" & _
                               " )" & _
                      " SELECT " & _
                               Chr$(34) & strFilePath & Chr$(34) & " AS FilePath," & _
                               Chr$(34) & strFileName & Chr$(34) & " AS FileName"
                               
    Forms(strUpdateFormName)(strUpdateControlName) = strFileName
    DoEvents

As you can see, the form name and control are set earlier.

The problem is that the form name is set with Me.Name and the ControlName is named (like "txtFilesFound").

The problem is that I am trying to use this form in an unbound subform so that I can simplify the interface and load the unbound subform based on the links on the left clicked.

But any attempt to substitute Me.Name with Frm_MainPage!ubSubForm (are any variant) fails with "Can't find the Form".

How would I change this to allow the reference into the subform?

Thanks. Sean.
 
When referencing subforms, you need to reference through the main form on which it resides. Not only that, but subforms reside within a "container" control, which name you need to use when referencing it.

Say the main form name is frmMain, the sub form name is frmSub, but then, in design view, you click the container, bring up the properties dialog (will say subform/subreport on top, I think), and the other tab, you'll find the name of the container containing the subform, which can be something quite different from the subform itself, say MySubForm

The "usual" referencing style, would then look something like this

Forms!frmMain!MySubForm.Form.txtTheControl

Using the Form keyword is essential when working with properties of the form, but can be omitted when referring to controls on the subform, but I'll use it anyway, as that reduces my confusion ;-)

"The Form or Report identifier is optional when referring to control properties. It is necessary, however, when referring to subform or subreport properties."


Then it's just to translate it to the referencing style you use now
[tt]
dim sMain as string
dim sSub as string
dim sControl as string
sMain = "frmMain"
sSub = "MySubForm"
sControl = "txtTheControl"

MsgBox Forms(sMain).Controls(sSub).Form(sControl).value[/tt]

Next thing, is probably to determine whether the form operates as a separate form vs as subform, and at least it can be either separate or subform, you could do

[tt]if not currentproject.allforms("frmSub").IsLoaded then
' it's not loaded as separate form, then
' probably as subform ;-)
end if[/tt]

Roy-Vidar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top