Subform in Procedure (1 Viewer)

Joshann

Registered User.
Local time
Today, 11:57
Joined
Mar 22, 2002
Messages
142
I know this has got to be a simple reference problem, but I just can't figure it out. I am trying to pass a nested subform to a procedure, but I keep getting a type mismatch error. Here's an example:

Code:
Call MyProcedure(Forms!MainForm.Form!Subform1.Form!Subform2)


Public Sub MyProcedure(frm as Form)
.
.
End Sub
 

boblarson

Smeghead
Local time
Today, 09:57
Joined
Jan 12, 2001
Messages
32,059
One, you shouldn't be trying to pass the FORM itself. What are you trying to do in the procedure? More than likely you need to pass something else, or do something else.

By the way your subform syntax is wrong too. The syntax is:


Forms!YourMainFormNameHere.YourSubformControlNameHere.Form.YourControlNameHere
(the space between the H and the e are from the forum doing weird things - it's not my typing)
 
Last edited:

KeithG

AWF VIP
Local time
Today, 09:57
Joined
Mar 23, 2006
Messages
2,592
Can you explain what your procedure does? A subform is a control on a form not an actual form. It think this may be causing your error.
 

Joshann

Registered User.
Local time
Today, 11:57
Joined
Mar 22, 2002
Messages
142
Here is a sample of some of the code that illustrates why I need to use the Form object:

Code:
Call MyProcedure(Forms!MainForm.Form!Subform1.Form!Subform2)

Procedure MyProcedure(frm as Form)
[INDENT]If frm.NewRecord = True Then
[INDENT]For Each ctl In frm.Controls
[INDENT]rst.AddNew
rst!NewValue = ctl.Value
rst.Update[/INDENT]
Next ctl[/INDENT]
End If[/INDENT]
.
.
End Sub

There are many forms that use this procedure. It works fine when the procedure is called from a main form like this:
Code:
Call MyProcedure(Me)

It just doesn't work for a subform.
 

Users who are viewing this thread

Top Bottom