Using ME in a public sub

  • Thread starter mattc66 via AccessMonster.com
  • Start date
M

mattc66 via AccessMonster.com

I have created a public sub that I want to reuse in different forms.

What I am running into is the use of: me.NameOfControl.

Dim stFrt As String

stFrt = Me.Carrier

The control name is the same in all the forms I want to reuse the code
however it is failing. How do I do this?

Matt
 
D

Douglas J. Steele

You need to pass an instance of the form to the sub.

Public MySub(WhatForm As Form)
Dim stFrt As String

stFrt = WhatForm.Carrier

....

End Sub


You then invoke the sub as:

Call MySub(Me)

or

MySub Me
 
M

mattc66 via AccessMonster.com

How would I make the WhatForm generic so that I can us the code in different
forms.

Matt
You need to pass an instance of the form to the sub.

Public MySub(WhatForm As Form)
Dim stFrt As String

stFrt = WhatForm.Carrier

...

End Sub

You then invoke the sub as:

Call MySub(Me)

or

MySub Me
I have created a public sub that I want to reuse in different forms.
[quoted text clipped - 8 lines]
 
D

Douglas J. Steele

It IS generic. As I said, you pass a reference to the form to the routine:

Call MySub(Me)

or

MySub Me


--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


mattc66 via AccessMonster.com said:
How would I make the WhatForm generic so that I can us the code in
different
forms.

Matt
You need to pass an instance of the form to the sub.

Public MySub(WhatForm As Form)
Dim stFrt As String

stFrt = WhatForm.Carrier

...

End Sub

You then invoke the sub as:

Call MySub(Me)

or

MySub Me
I have created a public sub that I want to reuse in different forms.
[quoted text clipped - 8 lines]
 
Top