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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pass subform name as variable to Module. 1

Status
Not open for further replies.

bsupport

Programmer
Dec 20, 2000
53
0
0
US
I need to pass the name of a subform or form, (reference different subforms or forms, depending on what procedure I'm running) to a SUB in a module. Can anyone help? [sadeyes] I have tried searching the Access forums and the Faq's with no luck. All of those reference a particular subform, I need the subform name passed to a procedure so it needs to be as a variable. Unless someone can tell me a better way of doing this. Thanks in advance.

-B [dazed] Who takes 7 seconds to develop,
7 mins to document,
7 hours to test,
7 months to fix will always blame the clock. s-)
 
You can store a form name in a String variable, which can then be passed to ... anything.

Access the form (given a string):

Code:
Dim strFormName as String

strFormName = "frmMYFORM"
Forms(strFormName)


For subforms, you may want to consider referencing the "main form->subform control->Form property" to get the subform, instead of directly referencing the subform. i.e.

Forms!frmMainForm!ctlSubFormControl.Form --
Find common answers using Google Groups:

 
Foolio12,

So, to pass the subform name frmSub, I would use:

name of variable that holds name of main form: frmMain
name of variable that holds name of subform: frmSub
name of control on subform: startDate

Forms!frmMain!frmSub.Form!startDate

Is this correct? I will go try this and get back with you.
Thanks. Who takes 7 seconds to develop,
7 mins to document,
7 hours to test,
7 months to fix will always blame the clock. s-)
 
Close.
Code:
Forms![frmMain]![ctlNameOfTheSubFormControl].Form![startDate]

Go to your "frmMain" design view, and click on the subform control (the big white box thing), and look for that name in the properties box. That is what should replace "ctlNameOfTheSubFormControl".

I guess you could just do:
Code:
Forms![frmSub]![startDate]
but if "frmSub" is open as a subform on two different main forms (something that actually happens in the app I'm developing), using the second method is ambiguous.

Brackets are all optional.

On the Access MVP web site they have a pretty comprehensive look at all this:

--
Find common answers using Google Groups:

 
Foolio12,

Ok, I guess I am not being clear enough. I need the [ctlNameOfTheSubFormControl] to be a variable, not the actual name of the control because the sub procedure and function routines where I will use it and will pass different subform names.

Thanks.

Who takes 7 seconds to develop,
7 mins to document,
7 hours to test,
7 months to fix will always blame the clock. s-)
 
Foolio12,

Thanks for your assistance, I really appreciate your response. I have found another thread, thread702-461372 that solved my problem. I used her suggestion to initialize a global and it worked great.

Again, thanks [bigsmile],
Bsupport Who takes 7 seconds to develop,
7 mins to document,
7 hours to test,
7 months to fix will always blame the clock. s-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top