Previous Thread

7/6/2006 11:29:40 AM    How do I reference a subform?
How do I programmatically reference a subform? 
 
This does NOT work: 
 
Public Sub CompareStrings(FormName As String, FormField As String) 
 
Dim ThisForm As SubForm 
 
Set ThisForm = Forms.(FormName) 
 
I get an error message: 
 
Microsoft Office Access can't find the form 'My Form Name' referred to in a 
 
macro expression or Visual Basic Code. 
 
Thanks for your help, 
 
Kan



7/7/2006 12:42:27 AM    Re: How do I reference a subform?
That's right. Subforms are not open in their own right, i.e. they are not 
 
part of the Forms collection. 
 
See: 
 
Referring to Controls on a Subform 
 
at: 
 
http://allenbrowne.com/casu-04.html 
 
for the general syntax, and the difference between a subform control and the 
 
form in that control. 
 
As far as your code goes, could you just pass the entire control and/or form 
 
reference to your function? 
 
Public Sub CompareStrings(frm As Form, ctl As Control) 
 
Debug.Print frm.Name 
 
Debug.Print ctl.Name, ctl.Value 
 
... 
 
You would then call it like this, regardless of whether you are in a main 
 
form's or a subform's module: 
 
Call CompareStrings(Me, Me.Text0) 
 
Or, if you are in the main form's module and want to pass a reference to the 
 
subform: 
 
Call CompareStrings(Me.[Sub1].Form, Me.[Sub1].Form!Text0) 
 
-- 
 
Allen Browne - Microsoft MVP.  Perth, Western Australia. 
 
Tips for Access users - http://allenbrowne.com/tips.html 
 
Reply to group, rather than allenbrowne at mvps dot org. 
 
"Kan D." <kand1973@hotmail.com> wrote in message 
 
news:%23nkNilRoGHA.2264@TK2MSFTNGP04.phx.gbl...