replacing the me for form name in code

  • Thread starter Thread starter JohnE
  • Start date Start date
J

JohnE

Hello. I am familiar with the use of me. as the form name. But, what I
would like to do is replace it with the proper terminology so it can be used
in modules and then make the Call instead. Unfortunately, it fails on Me.,
which is understandable.
How and what is the proper way of replacing the Me. in a module?
Thanks.
John
 
Assuming you've currently got something like:

Me!Textbox = SomeValue

try:

Sub MySub(WhatForm As Form, SomeValue As String)

WhatForm!Textbox = SomeValue

End Sub

You'd then invoke it as

Call MySub (Me, SomeValue)
 
Thank you for the quick response. I forgot to include the code I currently
had so it is here. This is inside the module and the Call ScrollCaption(Me)
is on the form's timer event. This is not working like it should. The
ScrollCaption would be called whenever the person switches to the training
part of the app. I replaced the Me. with frm.

Public MyCaption As String
Public Pos As Integer
Public ScrollText As String

Public Sub ScrollCaption(frm As Form)

MyCaption = frm.Caption
ScrollText = "... Training Session ..."
frm.TimerInterval = 100

With frm
.Caption = .MyCaption & " " & Mid(.ScrollText, .Pos + 1) &
Left(.ScrollText, .Pos)
.Pos = (.Pos + 1) Mod Len(.ScrollText)
End With

End Sub

What further is there that I would need for the replacing of Me?
Thanks again.
john
 
"not working like it should" doesn't say much...

You should indicate what does happen, and what you want to have happen
instead. If an error occurs, the complete error message should be given.

Looking at your code, though, you're mistakenly treating variable MyCaption,
Pos and ScrollText as properties of the form (which they aren't). You're
also continually appending to the end of the caption, which means it's
eventually going to get too long.

Public Pos As Integer
Const ScrollText As String = "... Training Session ..."

Public Sub ScrollCaption(frm As Form)

frm.Caption = Mid(ScrollText, Pos + 1) & Left(ScrollText, Pos)
Pos = (Pos + 1) Mod Len(ScrollText)

End Sub
 
JohnE said:
Thank you for the quick response. I forgot to include the code I currently
had so it is here. This is inside the module and the Call ScrollCaption(Me)
is on the form's timer event. This is not working like it should. The
ScrollCaption would be called whenever the person switches to the training
part of the app. I replaced the Me. with frm.

Public MyCaption As String
Public Pos As Integer
Public ScrollText As String

Public Sub ScrollCaption(frm As Form)

MyCaption = frm.Caption
ScrollText = "... Training Session ..."
frm.TimerInterval = 100

With frm
.Caption = .MyCaption & " " & Mid(.ScrollText, .Pos + 1) &
Left(.ScrollText, .Pos)
.Pos = (.Pos + 1) Mod Len(.ScrollText)
End With

End Sub


It would make more sense if you had posted this as a follow
up in your original thread.

Somehow, you merged the code for the form's Load event and
the code in the Sub procedure making a mess of it. Go back
and review the code I posted and see if you can make that
work before you start putting things in different places.

Besides, I thought you were going to scrap the idea of using
a timer in every form??
 
Back
Top