469,306 Members | 1,903 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,306 developers. It's quick & easy.

Passing the Me Keyword to a Public Function

A97, NT4.

I've seen an example of this posted here but I can't for the life of me
find it. If I have a lot of controls on a form which all require the same
After Update action, what syntax do you need to pass "Me" to the public
function in a module?

I've tried calling

Public Function libComboFilter(frmForm As Form_Form1) As String

libComboFilter = frmForm.Name
Debug.Print libComboFilter

End Function

from a form called "Form1" with

libComboFilter (Me)

but I get a type mismatch error. I've nothing specific to achieve, I'm just
trying to get the principle right.

Thanks.
Keith.
Nov 13 '05 #1
15 11684
Keith,
are you fishing for Me.ActiveControl? I would think you'd have to
assign that to a variable in your form's code module and then pass the
variable to your function... Something like

Dim strCtrlName as string
Dim strFormName as string
strFormName=me.name
strCtrlName = me.activecontrol.name

X=fSomePublicFunction(strFormName,strCtrlName)

then it's totally unambiguous.

Nov 13 '05 #2
pi********@hotmail.com wrote:
Keith,
are you fishing for Me.ActiveControl? I would think you'd have to
assign that to a variable in your form's code module and then pass the
variable to your function... Something like

Dim strCtrlName as string
Dim strFormName as string
strFormName=me.name
strCtrlName = me.activecontrol.name

X=fSomePublicFunction(strFormName,strCtrlName)

then it's totally unambiguous.


Well I could make it work like that but I could have sworn I saw some code
on here where the Me keyword was passed on it's own ... maybe I was
mistaken.

Many thanks for a speedy response.

Keith.
Nov 13 '05 #3
Try this:

Public Function MyFunction(frmObject)
MyFunction = frmObject.Name
End Function
Call it this way:
MyName = MyFunction(Me)
--

Ken Snell
<MS ACCESS MVP>

"Keith" <ke*********@AwayWithYerCrap.com> wrote in message
news:Xn************************@10.15.188.42...
A97, NT4.

I've seen an example of this posted here but I can't for the life of me
find it. If I have a lot of controls on a form which all require the same
After Update action, what syntax do you need to pass "Me" to the public
function in a module?

I've tried calling

Public Function libComboFilter(frmForm As Form_Form1) As String

libComboFilter = frmForm.Name
Debug.Print libComboFilter

End Function

from a form called "Form1" with

libComboFilter (Me)

but I get a type mismatch error. I've nothing specific to achieve, I'm
just
trying to get the principle right.

Thanks.
Keith.

Nov 13 '05 #4
Either
call libComboFilter(Me)

Or
libComboFilter Me

should work, although why you would use a public function for this when the
parameter type you are passing is Form_Form1 I don't know.

I would expect you to either have

Public Function libComboFilter(frmForm As Form) As String

or put the function in the form class module in which case you don't need to
pass a parameter.
--
Terry Kreft
MVP Microsoft Access
"Keith" <ke*********@AwayWithYerCrap.com> wrote in message
news:Xn************************@10.15.188.42...
A97, NT4.

I've seen an example of this posted here but I can't for the life of me
find it. If I have a lot of controls on a form which all require the same
After Update action, what syntax do you need to pass "Me" to the public
function in a module?

I've tried calling

Public Function libComboFilter(frmForm As Form_Form1) As String

libComboFilter = frmForm.Name
Debug.Print libComboFilter

End Function

from a form called "Form1" with

libComboFilter (Me)

but I get a type mismatch error. I've nothing specific to achieve, I'm just trying to get the principle right.

Thanks.
Keith.

Nov 13 '05 #5
I've been using this approach for years:

How to call a function and pass your form

Me.HelpLabel.Caption = "How is it going"

SomeFunction(Me)
-------------------------------------

Public sub SomeFunction(Calling as form)

Calling.HelpLabel.Caption = "Going really good"

Exit Sub

Hank Reed

Nov 13 '05 #6
Keith wrote:
A97, NT4.

I've seen an example of this posted here but I can't for the life of me
find it. If I have a lot of controls on a form which all require the same
After Update action, what syntax do you need to pass "Me" to the public
function in a module?

I've tried calling

Public Function libComboFilter(frmForm As Form_Form1) As String

libComboFilter = frmForm.Name
Debug.Print libComboFilter

End Function

from a form called "Form1" with

libComboFilter (Me)

but I get a type mismatch error. I've nothing specific to achieve, I'm just
trying to get the principle right.

Thanks.
Keith.


Should be:

Public Function libComboFilter(frmForm As Access.Form) As String


--
Tim http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "Whatcha doin?" - Ditto "TIM-MAY!!" - Me
Nov 13 '05 #7
"Ken Snell" <kt***********@ncoomcastt.renaetl> wrote:
Public Function MyFunction(frmObject)
MyFunction = frmObject.Name
End Function
Call it this way:
MyName = MyFunction(Me)


That's it, many thanks indeed Ken. Thanks also to all other respondees.

Keith.
www.keithwilby.com
Nov 13 '05 #8
This is bad practice, if you know the type of the argument your procedure
expects then you should declare the argument as that type, not as a variant
which is what this declaration is doing.

--
Terry Kreft
MVP Microsoft Access
"Grumpy Old Man" <ke*********@AwayWithYerCrap.com> wrote in message
news:Xn************************@10.15.188.42...
"Ken Snell" <kt***********@ncoomcastt.renaetl> wrote:
Public Function MyFunction(frmObject)
MyFunction = frmObject.Name
End Function
Call it this way:
MyName = MyFunction(Me)


That's it, many thanks indeed Ken. Thanks also to all other respondees.

Keith.
www.keithwilby.com

Nov 13 '05 #9
"Terry Kreft" <te*********@mps.co.uk> wrote:
This is bad practice, if you know the type of the argument your
procedure expects then you should declare the argument as that type,
not as a variant which is what this declaration is doing.


You're referring to the omission of "As Form"? I've included that and it
works fine. Thanks for your response Terry, much appreciated.

Regards,
Keith.
Nov 13 '05 #10
Terry - I concur wholeheartedly with defining argument types. I left it out
of the example as I wasn't sure if the called function would be used just
for a form, or also might be used for a report.

--

Ken Snell
<MS ACCESS MVP>

"Terry Kreft" <te*********@mps.co.uk> wrote in message
news:tq********************@karoo.co.uk...
This is bad practice, if you know the type of the argument your procedure
expects then you should declare the argument as that type, not as a
variant
which is what this declaration is doing.

--
Terry Kreft
MVP Microsoft Access
"Grumpy Old Man" <ke*********@AwayWithYerCrap.com> wrote in message
news:Xn************************@10.15.188.42...
"Ken Snell" <kt***********@ncoomcastt.renaetl> wrote:
> Public Function MyFunction(frmObject)
> MyFunction = frmObject.Name
> End Function
>
>
> Call it this way:
> MyName = MyFunction(Me)


That's it, many thanks indeed Ken. Thanks also to all other respondees.

Keith.
www.keithwilby.com


Nov 13 '05 #11
Ken,
Good point, but then I would at least go for As Object.
--
Terry Kreft
MVP Microsoft Access
"Ken Snell" <kt***********@ncoomcastt.renaetl> wrote in message
news:l8********************@comcast.com...
Terry - I concur wholeheartedly with defining argument types. I left it out of the example as I wasn't sure if the called function would be used just
for a form, or also might be used for a report.

--

Ken Snell
<MS ACCESS MVP>

"Terry Kreft" <te*********@mps.co.uk> wrote in message
news:tq********************@karoo.co.uk...
This is bad practice, if you know the type of the argument your procedure expects then you should declare the argument as that type, not as a
variant
which is what this declaration is doing.

--
Terry Kreft
MVP Microsoft Access
"Grumpy Old Man" <ke*********@AwayWithYerCrap.com> wrote in message
news:Xn************************@10.15.188.42...
"Ken Snell" <kt***********@ncoomcastt.renaetl> wrote:

> Public Function MyFunction(frmObject)
> MyFunction = frmObject.Name
> End Function
>
>
> Call it this way:
> MyName = MyFunction(Me)

That's it, many thanks indeed Ken. Thanks also to all other respondees.

Keith.
www.keithwilby.com



Nov 13 '05 #12
"Terry Kreft" <te*********@mps.co.uk> wrote:
Good point, but then I would at least go for As Object.


Terry,

I've used "As Form" and everything works fine. Would "As Object" be a
better option?

Regards,
Keith.
Nov 13 '05 #13
Not if it is just Forms you are passing, Ken was making the point that by
declaring the argument as a variant (which is the implicit data type if no
explicit declaration is made) he was leaving open the option to pass a
Report as well.

My point was that in that case declaring the argument as Object would be a
tighter declaration than as Variant.

If your procedure now works stick with it.

--
Terry Kreft
MVP Microsoft Access
"Grumpy Old Man" <ke*********@AwayWithYerCrap.com> wrote in message
news:Xn************************@10.15.188.42...
"Terry Kreft" <te*********@mps.co.uk> wrote:
Good point, but then I would at least go for As Object.


Terry,

I've used "As Form" and everything works fine. Would "As Object" be a
better option?

Regards,
Keith.

Nov 13 '05 #14
"Terry Kreft" <te*********@mps.co.uk> wrote:
Not if it is just Forms you are passing, Ken was making the point that
by declaring the argument as a variant (which is the implicit data type
if no explicit declaration is made) he was leaving open the option to
pass a Report as well.

My point was that in that case declaring the argument as Object would
be a tighter declaration than as Variant.

If your procedure now works stick with it.


Thanks for the clarification.
Nov 13 '05 #15
Yes, I concur.

--

Ken Snell
<MS ACCESS MVP>

"Terry Kreft" <te*********@mps.co.uk> wrote in message
news:DK********************@karoo.co.uk...
Ken,
Good point, but then I would at least go for As Object.
--
Terry Kreft
MVP Microsoft Access
"Ken Snell" <kt***********@ncoomcastt.renaetl> wrote in message
news:l8********************@comcast.com...
Terry - I concur wholeheartedly with defining argument types. I left it

out
of the example as I wasn't sure if the called function would be used just
for a form, or also might be used for a report.

--

Ken Snell
<MS ACCESS MVP>

"Terry Kreft" <te*********@mps.co.uk> wrote in message
news:tq********************@karoo.co.uk...
> This is bad practice, if you know the type of the argument your procedure > expects then you should declare the argument as that type, not as a
> variant
> which is what this declaration is doing.
>
> --
> Terry Kreft
> MVP Microsoft Access
>
>
> "Grumpy Old Man" <ke*********@AwayWithYerCrap.com> wrote in message
> news:Xn************************@10.15.188.42...
>> "Ken Snell" <kt***********@ncoomcastt.renaetl> wrote:
>>
>> > Public Function MyFunction(frmObject)
>> > MyFunction = frmObject.Name
>> > End Function
>> >
>> >
>> > Call it this way:
>> > MyName = MyFunction(Me)
>>
>> That's it, many thanks indeed Ken. Thanks also to all other
>> respondees.
>>
>> Keith.
>> www.keithwilby.com
>
>



Nov 13 '05 #16

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

13 posts views Thread by Abe Frohnman | last post: by
5 posts views Thread by blue | last post: by
12 posts views Thread by Andrew Bullock | last post: by
13 posts views Thread by Andy Baker | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by harlem98 | last post: by
1 post views Thread by Geralt96 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.