Now we are on to Variables.

  • Thread starter Thread starter TeeSee
  • Start date Start date
T

TeeSee

At the top of one of my form modules I have ....
Option Compare Database
Option Explicit
Private strItem As String

Am I correct in thinking that I can now use strItem in any procedure
within that specific form module? FOr instance if strItem is defined
as "TeeSee" in OpenForm then it would still be the same value on a
cmdClick event on the same form. Are there any tricks to doing so 'cos
I can't get it to work out.

Thanks
 
TeeSee said:
At the top of one of my form modules I have ....
Option Compare Database
Option Explicit
Private strItem As String

Am I correct in thinking that I can now use strItem in any procedure
within that specific form module? FOr instance if strItem is defined
as "TeeSee" in OpenForm then it would still be the same value on a
cmdClick event on the same form.
Yes.

Are there any tricks to doing so 'cos
I can't get it to work out.

You'd have to show us exactly what you coded. One possible error would be
to *redefine* strItem in the procedures. If you Dim it at the module level,
don't Dim it anywhere else in that module, or you'll just be creating a
separate, local veriable of the same name, hiding the module-level one from
that procedure.
 
Yes, yes, and what are the symptoms? - in that order.

Now I suspect the confusion relates to your statement: '.. if strItem is
defined as "TeeSee" in OpenForm ...' What exactly do you mean by that?

If you mean that you have a code line similar to the following in the Open
event

Private Sub Form_Open(Cancel As Integer)
strItem = "TeeSee"
End Sub

then everything should work just fine, although you might want to consider
defining the string as a constant in the declaration section if its value
never changes.

If however you are referring to a DoCmd.OpenForm then short of passing
"TeeSee" as OpenArgs I can't see how you are managing this.

Rod
 
You'd have to show us exactly what you coded.  One possible error wouldbe
to *redefine* strItem in the procedures.  If you Dim it at the module level,
don't Dim it anywhere else in that module, or you'll just be creating a
separate, local veriable of the same name, hiding the module-level one from
that procedure.

Thanks Dirk ..... I had four Dims. One at the module level, two at the
sub level and me!
 
Back
Top