A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » New Users
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Now we are on to Variables.



 
 
Thread Tools Display Modes
  #1  
Old January 20th, 2009, 01:51 AM posted to microsoft.public.access.gettingstarted
TeeSee
external usenet poster
 
Posts: 40
Default Now we are on to Variables.

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
  #2  
Old January 20th, 2009, 04:11 AM posted to microsoft.public.access.gettingstarted
Dirk Goldgar
external usenet poster
 
Posts: 2,529
Default Now we are on to Variables.

"TeeSee" wrote in message
...
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.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)

  #3  
Old January 20th, 2009, 04:12 AM posted to microsoft.public.access.gettingstarted
Rod Plastow
external usenet poster
 
Posts: 195
Default Now we are on to Variables.

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
  #4  
Old January 20th, 2009, 01:25 PM posted to microsoft.public.access.gettingstarted
TeeSee
external usenet poster
 
Posts: 40
Default Now we are on to Variables.

On Jan 19, 10:11*pm, "Dirk Goldgar"
wrote:
"TeeSee" wrote in message

...

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.

--
Dirk Goldgar, MS Access MVPwww.datagnostics.com

(please reply to the newsgroup)


Thanks Dirk ..... I had four Dims. One at the module level, two at the
sub level and me!
  #5  
Old January 20th, 2009, 09:57 PM posted to microsoft.public.access.gettingstarted
troy23
external usenet poster
 
Posts: 55
Default Now we are on to Variables.

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


On 20 Jan, 00:51, TeeSee wrote:
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


 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 01:25 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.