Using ME in a public sub

  • Thread starter Thread starter mattc66 via AccessMonster.com
  • Start date 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
 
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
 
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]
 
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]
 

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

Back
Top