Now we are on to Variables.

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
 
D

Dirk Goldgar

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.
 
R

Rod Plastow

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
 
T

TeeSee

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!
 
T

troy23

If you want to use the variable in different forms then you will have
to hold it in a separate module. If it is local to one form then
declaring it at the top will be fine.


For FREE Access ebook and videos click here
http://access-databases.com/ebook
 

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

Top