passing Form object into function

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.
 
L

Larry Linson

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
 
G

Guest

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




.
 
V

Van T. Dinh

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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top