Use and Display Data in table other than one being used

WilRel

Registered User.
Local time
Today, 18:17
Joined
Dec 24, 2011
Messages
18
A Very good day to All and may I welcome myself.

I'm familiar with "Clarion for Windows", got a good sence of logic , but been trying, when time permits, to shift myself to Access, -Yes after ALL THESE YEARS!!! . I surely hope that all you pro's can help me, well, just to get started.

My question that I would like to ask is: There is a certain amount of, call it "Global Variables" that I need to use throughout the Data Base and would like to keep it in one place, like a Table called "Global Variables" ( or maybe an other place where it can be stored).

The problem is that when I'm in a Form using a certain Table and want to use or just show the value of a item in "Global Variables", how would I be going about and how would the Control Source property be looking:confused:?

I'm using Access 2003 and would appreciate your help.

Thanx:)
 
Place your Global Variables in a Separate Module, not a Table.

Then you can call the Varialbe by its name.
 
A Very good day to All and may I welcome myself.

I'm familiar with "Clarion for Windows", got a good sence of logic , but been trying, when time permits, to shift myself to Access, -Yes after ALL THESE YEARS!!! . I surely hope that all you pro's can help me, well, just to get started.

My question that I would like to ask is: There is a certain amount of, call it "Global Variables" that I need to use throughout the Data Base and would like to keep it in one place, like a Table called "Global Variables" ( or maybe an other place where it can be stored).

The problem is that when I'm in a Form using a certain Table and want to use or just show the value of a item in "Global Variables", how would I be going about and how would the Control Source property be looking:confused:?

I'm using Access 2003 and would appreciate your help.

Thanx:)

If you want to declare global variables, an easy way to do it is in a module. The variables defined in the module will be available to all of the forms in your program. Below is a snippet from the module used for zscalendar.

Option Compare Database 'Use database order for string comparisons
Option Explicit

Const CALENDAR_FORM = "zsfrmCalendar"

Type udDateType
wYear As Integer
wMonth As Integer
wDay As Integer
End Type


Private Function isFormLoaded(strFormName As String)
isFormLoaded = SysCmd(SYSCMD_GETOBJECTSTATE, A_FORM, strFormName)
End Function
 
'Global Variables

Public UndoHits As Single
Public TotalActive As Long
Public intTotalRecords As Integer
Public strCurrPt As String
Public DDate As Date
Public SCSwitch As Boolean


'Global Constants

Public Const VAT = .05
Public Const Time_Zone = "Eastern"
Public Const Currency = "USD"
 
Last edited:
If you want to declare global variables, an easy way to do it is in a module. The variables defined in the module will be available to all of the forms in your program. Below is a snippet from the module used for zscalendar.

Thanx for responding, but I don't understand the quote you posted. I can't see where the "global variables" are used in the function and how.

What I have done, is created a module and defined variables, say one of them is GlobalDate.

How and where would I set the value. What I do have in mind is to set the value to a value stored in a, let say a CONFIG file. So it needs to be done when the Database starts to run, supposedly in the beginning of the MAIN MENU form. (Maybe by using a macro, and if so, under which event would you set this )

Secondly, when this value is set and I want to display it in a Form, I'm thinking of using a Text Box and set the Control Source to this value, but when I type in "= GlobalDate" I still gets "#NAME?" shown when running?

Would you do it in a other way?
 
'Global Variables

Public UndoHits As Single
Public TotalActive As Long
Public intTotalRecords As Integer
Public strCurrPt As String
Public DDate As Date
Public SCSwitch As Boolean


'Global Constants

Public Const VAT = .05
Public Const Time_Zone = "Eastern"
Public Const Currency = "USD"

Hi MissingLinq

I would like to thank you for your reply. It sure gives me an idea of how the syntax should look like, but I would also like to know how to use the names, if not in CODE, but in the input Control Source field supplied in the editing window.

When I type say "= DDate" it gives me, when runned, "#NAME?"

Why?
 
It would appear that you cannot use a Global Variable in a Control Source.
 
Ok, so to display the value of the Global Var, you need to assign it manually to a text box.

I can think of a few ways, but has obviously not done it yet.

1. I can thus only use a Unbound Text field, or can you use a label instead?
2. Assigning the value could maybe be done by using CODE to set the Property?
3. How and where would you do it then?

thanx again.
 
You've given us a lot of info but haven't really given us a concrete example of what you need to do. If, for example, you want to assign the Value of a Global Variable to a Bound Textbox whenever a New Record is created, you can do this thru code:
Code:
Private Sub Form_Current()
 If Me.NewRecord Then Me.MyDate = DDate
End Sub
Keep in mind that before doing this the Value for the Global/Public Variable has to be set, somewhere within the database. If this Value is static, such as the value of Pi, for instance, you should use a Global/Public Const instead, assigning it a value as shown above, inside of a Standard Module. You'd then assign it to a Control in the same manner as you would with a Global Variable.

BTW, you may have noticed that Global and Public are used interchangeably. Global is the older term and is still recognized by VBA in order to keep Access backwards compatible.

Linq ;0)>
 
Hi Linq

I do appreciate your help. Slowly I'm getting there, but there seems to be one more hurdle for me to understand the new syntax.

Consider the following:
I have a Form that that lists all the employees currently active. To show the user the Active Date, because its not always the current system date, I want to show the Active Date [ADate] on the form.

In my query, I filter the entries of the employees' [StartDate], which is not the same as the ADate, but still applies to the Active Period, against a value that I have saved in a table named [GlobalValues] and then I display the result in the Form. (The value of ADate can also be changed during the program, so it can not be a constant. This is done in a seperate Form just for the changing purpose.)

Just to be certain

1. Where will you save/store the value ADate, in the Table or still as a Public Variable, because there are some other Values that need to be stored in a table and retrieved everytime the program starts, eg. cofiguration values like Company Rules. If I cannot directly link the Control Source of the Text box to a Public Variable, is there any advantage of keeping it in a Public Variable rather than in a Table?

2. Can you create a Bound Text Box that is bound to a Private Variable rather then bound to a value in a table. That is how I understand it. The Private Variable, say [DisplayDate] will get the value of ADate and then displays it?

3. If so, under what ENVENT will you declare the Private Variable and under what EVENT will you set the value.

Thanx Again

WR
 
If you want to store the values in a Table you will need the function DLookUp to return that vale. This would not be my prefered choice.

I would create a separate module to store Both Public Constants and Variables.

As previously stated if you were to store Pi then it would be a constant. Its value would be set at the same time you you create the Constant.

A variable cam be set or changed at any time.

It the Variable was aDate then to display it on a Form use the following in the On Open Event of the Form.

Me.TxtBoxName = aDate.

Other Events could also be used depending on your circumstances.

Hope this Helps.
 
Last edited:
:) Thanx again RainLover and MissingLinq.

You sure did show me enough syntax and directions to get a good start and if it wasn't for me going on a 700km trip tomorrow, I'd be most probably still busy coding.

Any way. Hope your Christmas was blessed and the very best for the new year.
Regards

WR:cool:
 

Users who are viewing this thread

Back
Top Bottom