Question : Module to control variable forms - errors passing form name

Hi All,

I am attempting to create a module to handle particular form properties in the same way for any given form.

Basically, I have a main form which I am creating to expand and shrink in a semi annimated way based the user clicking tabs (buttons) and each time the form expands it shows and drags with it a different subform.

(hope I've explained that well enough)

Well the very basic code I have to do this works very well sitting behind the form but I want to create the code to accept a variable form name so I created a module to call instead of creating the proceedure all over again for each and every subform on the main form.

However I am getting all kinds of errors when trying to pass the forms names to the module. (the main form and its subform)

Sample of the code below.

I am not sure if I am calling it correctly, defining the variables correctly or what but I either get "type Mismatch" with the call line or "Invalid Qualifier" on the strSubform.Visible = True line in the module depending on all the ways I have tried to define the variables (as string, as form) etc.

Any help is greatly appreciated!
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
'Call the module
Private Sub Button_Click
   Call ExpandForm(Me, Me.Form_Subform)
End Sub
 
'-------------------
'The module
Public Function ExpandForm(strMainForm As Form, strSubform As Form)
 
strSubform.Visible = True
 
strMainForm.InsideWidth = 8000
strSubform.Left = 500
Wait 1
strMainForm.InsideWidth = 8500
strSubform.Left = 1000
Wait 1
strMainForm.InsideWidth = 9000
strSubform.Left = 1500
Wait 1
 
'this just continues on to the desired form width and drags the subform with it
 
End Function

Answer : Module to control variable forms - errors passing form name

try this

Public Function ExpandForm(strMainForm As String, strSubform As String)
 
Forms(strMainForm).Controls(strSubform).Visible = True
 
With Forms(strMainForm)
     .InsideWidth = 8000
     .Controls(strSubform).Left = 500
Wait 1
     .InsideWidth = 8500
     .Controls(strSubform).Left = 1000
Wait 1
     .InsideWidth = 9000
     .Controls(strSubform).Left = 1500
Wait 1
 
'this just continues on to the desired form width and drags the subform with it
 
End Function

and call it passing the forms' NAMES instead of the forms objects themselves

Call ExpandForm(Me.Name, subFormControlName)

remember that the subform's actual names (in the database window) is irrelevant here, and all that matters is how you called the sub-form control on the main form's surface
Random Solutions  
 
programming4us programming4us