Form name in variable

  • Thread starter Thread starter jokobe
  • Start date Start date
J

jokobe

I use a (sub)form in different parent forms, and to get the value in a field
I want to put the form name in a variable.
For example:

[form1]![formname1]![controlname].rowsource = sqlstr
or in a different form:

[form2]![formname2]![controlname].rowsource = sqlstr

How is it possible to work like this:

StrForm = me.actualform.name
strform![controlname]. rowsource = sqlstr

thanks in advance for any helpful hint...
 
Dim strForm As String
Dim strControl As String
strForm = "Form1"
strControl = "Text0"
Forms(strForm).Controls(strControl)
 
Do you know what the form name will be each time -- is it a fixed name? If
yes, just set the variable to the string of that name:

strForm = "NameOfYourForm"


Or, you can use the Forms collection and identify the specific item by name:

Forms("NameOfYourForm")!NameOfControl.RowSource = sqlstr
 
thanks for your fast answer, that save my day...

jokobe

Allen Browne said:
Dim strForm As String
Dim strControl As String
strForm = "Form1"
strControl = "Text0"
Forms(strForm).Controls(strControl)

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

jokobe said:
I use a (sub)form in different parent forms, and to get the value in a
field
I want to put the form name in a variable.
For example:

[form1]![formname1]![controlname].rowsource = sqlstr
or in a different form:

[form2]![formname2]![controlname].rowsource = sqlstr

How is it possible to work like this:

StrForm = me.actualform.name
strform![controlname]. rowsource = sqlstr

thanks in advance for any helpful hint...
 
Back
Top