Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How long do Publics defined in stand alone class modules persist 2

Status
Not open for further replies.

SBendBuckeye

Programmer
May 22, 2002
2,166
0
0
US
I gave defined some global variables in a stand alone class module (eg Public gintVar1 As Integer, gstrVar2 As String, etc). Do they not reset when the form is closed and I am back at the Access main screen with tables, queries, forms, etc visible? I am getting runtime errors if I run the form again because when I go to set them up in form load processing they still exist.

How can I reset them if they do indeed persist?

Thanks in advance for any help!
 
Hi

Public variables in stand alone code modules permanently exist and are frequently used to pass information between forms.

Just what are you doing in the On Load events of your form to cause the error, and what is the error?

Post the code and I'll seee if I can help more

Regards

Tom
 
Thanks for the info. I guess I was expecting them to disappear when the form closed similarly to form module public declarations. Once you say that it makes sense that they would persist for the current session.

I didn't mean to mislead, I'm not actually getting an error message, the fact they persist is triggering error messages I put into the code to detect multiple instances. An example would be more than one control on a form flagged as the primary key.

What I really want to do is to declare a set of globals to be used by all of my forms. I thought I could standardize this process by using a standard module or is there a better way to do this?

Thanks again for your help!



 
A standard set of globals in a stand-alone code module is what I always use for information that I want to be able to share between many forms. It is the simplest way to handle the problem of sharing data and works fine.

It also has the advantage hat as the application expands and more forms get added, then you already have the structure for sharing data, without having to amend any of your existing forms.

Glad to be of help.
 
I, on the other hand tend to just pass UDT's containing the necessary between forms. After all, if you are progressing from form to form, through 'code', the code should 'know' what info the target (form or procedure) needs. Encapsulating the necessary info in a UDT assures that the info required is available to the called procedure (even if the procedure is a FORM!) and that 'foregin' info is not available for (inadvertnt) modification.

Besides, it seems (to me) that it is MUCH more consistient with OOP.

MichaelRed
m.red@att.net

There is never time to do it right but there is always time to do it over
 
Thanks for that addition Michael

Perhaps I should have mentioned that I have many forms each of which can be called from many other forms, and that the called form behaviour is dependent on subsets of these global variables. At the time of setting the global variables up I do not know which forms are going to be called, but the subset is known.

It also struck me that a good number of visitors to this site might not know what you meant by UDT or how to go about it. Might be worth posting a small example to help others along.

Tom
 
Michael,

I would be interested in an example showing how you define them, call them, etc.

Thanks,

SBendBuckeye
 
I, too, have been following this thread, but don't know what UDT stands for. I looked in my VB book, but found nothing other than User-defined Data Types. Is that what you're refering to? (It fits.)

Rodger Fields
Rodger Fields
Software Engineer
Pflugerville, Texas (suburb of Austin)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top