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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dimensioning using "Public" in standard module? 2

Status
Not open for further replies.

gusbrunston

Programmer
Feb 27, 2001
1,234
US
[tt]
Hi:

I'm trying to go from one form to another and carry forward values in variables to the new form.

My books suggest using "Public" instead of "Dim" in order to make the variables available to all forms in the "project".

Doesn't work for me. I'm using DAO in Access2000. I forgot to write down the specific error message, but I'll have it if you need it.

Appreciate any help.

Thanks, [glasses] Gus Brunston, using Access2000 Intermediate skills.
 
Hi gus,

The keyword here is 'scope' - what scope does a variable have?

If you define (dim) a var on a form, then that variable can be used throughout that form in all functions/subs in that form ONLY, other forms can't see it.

You need a Public variable that the whole APPLICATION can 'see'.

You define Application wide variables in a module just as your books advise.

i.e. 'public x as string'

Do this in a module.

Regards,

Darrylle "Never argue with an idiot, he'll bring you down to his level - then beat you with experience." darrylles@totalise.co.uk
 
[tt]
Hi Darrylle:

Thank you so much.

I was trying to use "Public" in an event procedure of the first form.

When I selected Modules from the object list and used "Public" in there, it all works like a charm!

I'm wondering if I should release the space after I'm through with these variables...maybe, varMyVariable = ""?

Thanks again. [glasses] Gus Brunston, using Access2000 Intermediate skills.
 
Hi Gus,

No - leave memory management to Access (or it's VB part).

Regards and you're welcome,

Darrylle

"Never argue with an idiot, he'll bring you down to his level - then beat you with experience." darrylles@totalise.co.uk
 
[tt]
Thank you, Darrylle.

Can I impose on you for one more question about this?

The last thing I use the variables for is to explain some transactions in a msgbox for the user.

A currency variable seems to lose it's currency format in the msgbox. It comes out with no decimal places unless the pennies are great than zero.

e.g., $400.00 is displayed as 400
$400.10 is displayed as 400.1

How can I restore the currency format in the string I build for the msgbox?

I think it's probably with quotation marks, comma, brackets or some combination, but I can't find it in my A2K books.

I do appreciate your help.

Have a happy holiday season! [glasses] Gus Brunston, using Access2000 Intermediate skills.
 
gusbrunston,

To answer your formatting woes, use something like the following:

strMsg = "This part of the message is text. You want the currency amount of " & Format([currency field], "Currency") & " displayed as such." Only two things are infinite, the universe and human stupidity, and I'm not sure about the former. (Albert Einstein)

Robert L. Johnson III, MCP, Network+, A+
Access Developer/Programmer
robert.l.johnson.iii@citigroup.com
 
[tt]
Hi, Robert:

Thank you for the help with formatting.

I'm at the point in development where I need to trap invalid entries and insert message boxes to inform users. So I'm learning now about strings and things.

Your answer was helpful. [glasses] Gus Brunston, using Access2000 Intermediate skills.
 
A somewhat more tedious approach to passing variables is to leave the 'originating' form open and just reference the values by use of the 'fully qualified' names (w/ Forms.frmName. ... ). This DOES require chewcking that the 'originating' form is open prior to the assignment, and some exception handling when it is not, but avoids the generation of "public" variables

Another technique is to have a (temporary) recordset which holds the variabls to be transferred and simply reference the recordset, again, with the necessity / expectation of checking for the existance.

Finally, I would generally NOT trust the 'memory management' to Ms. A., not from the memory perspective, but from the need to know that the information is both correct and current when referenced.

And, the post script. If you decide to use 'public' storage, it is esaier (for me at least) to generate a UDT to hold the individual elements (variables) for the 'transfer'), as the use of the UDT name generate the prompt for the individual element item names, so they can (easily) be picked from the drop down list. It also makes the "destruction" easier, as you only need to set the type to nothing, rather than each item within the type.

MichaelRed
m.red@att.net

Searching for employment in all the wrong places
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top