Form name in variable

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...
 
A

Allen Browne

Dim strForm As String
Dim strControl As String
strForm = "Form1"
strControl = "Text0"
Forms(strForm).Controls(strControl)
 
K

Kardan via AccessMonster.com

Hi,

Try this;

Me.Parent.Controls(ControlName).RowSource = sqlstr

Regards

Richard
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...
 
K

Ken Snell MVP

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
 
J

jokobe

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...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top