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

instantiate a form object by its name in MS Access

Status
Not open for further replies.

Zirak

MIS
Feb 3, 2003
164
US
Hi,
I am trying to build a wizard in ms access. The wizard wil have several forms which load as subform one by one in the main parent form.
Any way, before moving to the next form I need to pass the variables from the previus form.
I am trying to write a resuable module so that I can apply to other sections of my application (other wise I could have used public variables).
In order to do so I want to loop through the controls of each form (before loading the next one) and add the variables to a collection object for further retrival on the next form.
The problem I am facing is that in order to write a function or a sub that will get the form name and add all its controls to a collection I have to instantiate a form by its name. I am trying to use the below code but I get a Type mismatch error.
Public Sub SaveFormData(strFormName As String)

Dim ctl As Control
Dim key As String
Dim value As String
Dim f As New Form


Set f = CurrentProject.AllForms(strFormName)

For Each ctl In f.Controls

If ctl.ControlType = acTextBox Or ctl.ControlType = acComboBox Then
key = ctl.Name
value = ctl

NewWizardCol.Add value, key
End If

Next ctl

End Sub

if I use the below code to instantiate the form every thing works fine:
set f=Form_frmProductDupCheck


Any ideas how I can instantiate the form using its name. (I'm working in MS Access 2000)

Thanks
 
CurrentProject.AllForms(strFormName) is an AccessObject, not a Form.
The wizard wil have several forms which load as subform
When the subform is still loaded, you can try something like this (in the main form):
For Each ctl In Me(strFormName).Form.Controls



Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Thank you for your reply,
I actually did what you mentioned buth the problem is that i will have to cut and paste the code in each subform for every wizard. As you can imagen its going to be difficult to maintain. Rather, I want to have a function that gets the form name and populates the collection with the variables.

Thanks
 
Have you tried to leave the subforms opened but hidden ?

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
In order to load the next subform I set the Sourceobject of the subform to the new form. Is there any way to keep them open? The only way that I know is to have all subforms open is to have them all directly on one another and make them visible or invisible. But thats not the right way to do it or is it?!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top