Wrox Programmer Forums
|
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 12th, 2005, 02:38 PM
Authorized User
 
Join Date: Jul 2004
Posts: 46
Thanks: 0
Thanked 1 Time in 1 Post
Default Global/Public Constants

I hope someone can suggest a way around a seemingly intractable problem. I have database that opens a form (frm_progress) from which the user selectes an area (North, South, etc) from a combo box (Combo13). This area is then used to point the subsequent VBA, SQL queries, Forms and Reports to the relavnt data tables. I would like to store the value of the combo box in a variable that is available to all modules (Class or otherwise). I have tried

Public Const area As String = Forms!frm_progress!combo13

but, of course, that is rejected. I am sure there MUST be a way to do it rather than putting 'area = Forms!frm_...' etc in each module after declaring 'Public area as String'

Can anyone help?


 
Old May 12th, 2005, 03:02 PM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 168
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi
Declare a public variable named Area
Then in Combo13 AfterUpdate event assign value to Area Variable

Public Area As String

Area=combo13

-vemaju


 
Old May 12th, 2005, 03:11 PM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 564
Thanks: 0
Thanked 4 Times in 4 Posts
Default

I always find it good to declare all my global variables at the top of a module, outside of any function or sub procedure. This just helps me keep them all together and controlled - well as much control as you can have with a global variable. Vemaju is right on the money!

Mike
EchoVue.com
 
Old May 12th, 2005, 04:27 PM
Authorized User
 
Join Date: Jul 2004
Posts: 46
Thanks: 0
Thanked 1 Time in 1 Post
Default

Thank you both. When it's written down, it's obvious - it just necer occurred to me that when you set a global variable, it's value remains set. Back to school for me, i think


 
Old May 13th, 2005, 12:31 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 168
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi
It is a good practice to have one module in your project, where you declare all public constants and public variables and nothing else.
I always name this module with name Globals

-vemaju

 
Old May 13th, 2005, 10:06 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Hi,

   This discussion is very instructive. Can you tell me more about what the code in the module would look like that would take the value from the combo13 after update event?

Thanks,




mmcdonal
 
Old May 13th, 2005, 12:22 PM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 564
Thanks: 0
Thanked 4 Times in 4 Posts
Default

The Global variable would be declared in the Globals module, however the value would need to be assigned based on some event. You could just have a on onClick even associated with the combo box and then set that value = to your Global Variable. The Global variable is initialized when the application is started and is available from anywhere in the application...

This brings up an interesting problem though. While Global variables definitely make life a little easier. In programming circles particularly with the advanced object oriented languages like Java, the belief is that Global variables should be avoided where ever possible. The reason being that because the variable is accessible from everywhere, in complex programs, you run the risk of the value not being updated or being changed while the variable is 'en-route' to where you intend to reference it.

Mike

Mike
EchoVue.com





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to declare the global variable in global.asax? calyn_gately ASP.NET 3.5 Basics 0 August 6th, 2008 08:06 PM
public article - public articledetails _keysersoze_ BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 0 September 8th, 2007 08:38 AM
declaring constants and pointer constants proslambano BOOK: Ivor Horton's Beginning Visual C++ 2005 3 March 6th, 2007 03:32 PM
Constants in XSL austinf XSLT 2 August 29th, 2006 06:04 AM
DriveType constants fordrs3 Beginning VB 6 1 June 22nd, 2003 08:23 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.