Referencing a form from an argument...!!!!

Randomblink

The Irreverent Reverend
Local time
Today, 08:55
Joined
Jul 23, 2001
Messages
279
Public Function SetGenerics(frm As Form, ctl As Control, Optional subfrm As Control)
Dim strColCnt As Integer, strColWdt As String, strRow As String, strTag As String, strlbl As String
Dim ctrl As Control, lblADD As Label, lstADD As ListBox, lblDELETE As Label, lstDELETE As ListBox
On Error GoTo Err_SetGenerics

Set ctrl = Forms!frm.Controls!subfrm

With ctrl
.SourceObject = somevariable
.LinkMasterFields = somevariable
.LinkChildFields = somevariable
End With

End Function

Here is how I call it:
SetGenerics Me, cmbSelectProjectAssignments, subform_GenericListing

or :
Call SetGenerics (Me, cmbSelectProjectAssignments, subform_GenericListing)

Either one gives me the same thing...

Ok...
obviously, the REAL function does a whole lot more...
But, this ONE line keeps giving me a real pain...
It says:

Microsoft Access cannot find the form 'frm' referred to in a macro expression or Visual Basic Code.

What am I doing wrong...????!!!!

I tried swapping out the lines:

Set ctrl = Forms!frm.Controls!subfrm

With ctrl
.SourceObject = somevariable
.LinkMasterFields = somevariable
.LinkChildFields = somevariable
End With

with:

With frm!subfrm
.SourceObject = somevariable
.LinkMasterFields = somevariable
.LinkChildFields = somevariable
End With

But then it can't find the field 'subfrm' yadda yadda yadda...

Where have I failed oh great ones...???
 
Brian,

This statement
<<
Set ctrl = Forms!frm.Controls!subfrm
>>
will not work.

To refer to a control, the general statement is:
Forms![SomeFormName].Controls("SomeControlName")

SomeFormName and "SomeControlName" are basically **String** values. You can NOT pass a Form or a Control and use it as a string.

If you really want to find a specific control on a specific form do this:
<<
Public Sub FindControl(PfrmTemp As Form, PstrControlName As String)
Dim ctlWork As Control

For Each ctlWork In PfrmTemp.Controls
If ctlWork.Name = PstrControlName Then
' Yipee ! Found the control !
End If
Next ctlWork

End Sub
>>

Call FindControl(Me, "txtSomeTextBox")

>>

HTH,
RichM
 

Users who are viewing this thread

Back
Top Bottom