How to pass the me parameter

M

Michel

Hi I've a function in a module and I'd like to pass the me parameter of a
form

Call MyFunc(Me)

PublicSub MyFunc(myMe)
debug.print(myMe.CurrentRecord)
End Sub

If I do this I've an error
Object doesn't support this property or method
Is there a way of doing it?
I know that I can do

Call MyFunc(Me.name)

PublicSub MyFunc(name As String)
debug.print(Forms(name).CurrentRecord)
End Sub


But is it possible to pass directly the me?

Michel
 
W

Wayne Morgan

If you were going to do it, the sub should be

Public Sub MyFunc(myMe As Form)

However, I've heard of some problems with this not working correctly. In
which case, the work around is to pass the name of the form.

Call MyFunc(Me.Name)

Public Sub MyFunc(myMe As String)
Debug.Print Forms(myMe).CurrentRecord
End Sub
 
R

rkc

Wayne said:
If you were going to do it, the sub should be

Public Sub MyFunc(myMe As Form)

However, I've heard of some problems with this not working correctly. In
which case, the work around is to pass the name of the form.

Do you have any examples of when passing a Form object
caused problems?
 
M

Michel

Well in the sample that I wrote

In the form have a call like this
Call MyFunc(Me)


And in an other module this function
PublicSub MyFunc(myMe)
debug.print(myMe.CurrentRecord)
End Sub

Then he doesen't recognise the myMe.CurrentRecord
And if I write MyFunc(myMe As Form) I'll get an wrong type when I pass the
Me as parameter...
The only way that I found to make it work is to pass the form name. But why?

Michel
 
R

rkc

Michel said:
Well in the sample that I wrote

In the form have a call like this
Call MyFunc(Me)


And in an other module this function
PublicSub MyFunc(myMe)
debug.print(myMe.CurrentRecord)
End Sub

Then he doesen't recognise the myMe.CurrentRecord
And if I write MyFunc(myMe As Form) I'll get an wrong type when I pass the
Me as parameter...
The only way that I found to make it work is to pass the form name. But why?


Post your actual code instead of some made up example with typos.

I have never seen Sub MyFunc(myMe as Access.Form) fail.
 
B

Barry-Jon

Your procedure is set to accept one argument (myMe). You need to
specify a type for the argument. As it is you are passing it as a
variant. You should set the argument type (myMe as Form). You then
need to call it like so;

Call MySub(me.form).

I have never had any problems with this.

Incidentally Me is not a parameter or property of a form. Me is a
reference to the current form in a forms module, current report in a
report module etc...
 
M

Michel

Thank's for your help,

I found where the problem come from
If you do the call like this
Call MyFunc(Me)
if works great but if you do the call without the "Call" like this
MyFunc(Me)
You get the error "Type mismatch"
Is there a raison for this?
I thought that the "Call" was only necessary if you had more than one
parameter.

Fo Barry: it doesn't change anything if you set or not the type of the
argument but I agree it's better to do so.

Michel
 
W

Wayne Morgan

Some of the other MVPs have reported seeing problems with passing Me. Some
would occasionally get crashes and others would get a type mismatch error.
The work around was to pass the name.

Both calls to the function ought to work. I suspect you are running across
what I mentioned above.
 
D

Dirk Goldgar

Wayne Morgan said:
Some of the other MVPs have reported seeing problems with passing Me.
Some would occasionally get crashes and others would get a type
mismatch error. The work around was to pass the name.

Both calls to the function ought to work. I suspect you are running
across what I mentioned above.

I have to disagree with you, Wayne, when you say that both calls should
work. Both of *these* should work:

Call MyFunc(Me)
MyFunc Me

But this should *not* work:

MyFunc (Me)

The extraneous parentheses will force the Me reference to be evaluated
and its "value" to be passed. The default property of a Form object is
its Controls collection, so what is passed in that last statement is a
Controls collection, not a Form object.
 

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