passing Form object into function

  • Thread starter Thread starter Grant
  • Start date Start date
G

Grant

What would be wrong with the following statement:

EnableControls (Me.Form)
where EnableControls accepts the following:
Function EnableControls(frm As Form)

Thanks in advance for the replies.
 
Assuming that this code is in a Forms module, try:

EnableControls (Me)

A Form does not have a Form Property. A Subform Control has a Form
property, but your expression clearly does not reference a Control.

Larry Linson
Microsoft Access MVP
 
It tells me Runtime error 13. Type mismatch.
-----Original Message-----
Assuming that this code is in a Forms module, try:

EnableControls (Me)

A Form does not have a Form Property. A Subform Control has a Form
property, but your expression clearly does not reference a Control.

Larry Linson
Microsoft Access MVP




.
 
I occasionally have problems using "Me" this way (not sure
why). Therefore, I tend to pass the Form name and re-
construct the Form Object in the Sub / Function.

Something like:

Function EnableControls(strFormName As String)

Dim frm As Access.Form

Set frm = Forms(strFormName)

....

and when you call the Sub / Function, you can simply use:

Call EnableControls(Me.Name)

You said it was a Function but I think it is more correct
to use a Sub rather than a Function.

HTH
Van T. Dinh
MVP (Access)
 
Back
Top