Global Defaults

psycoperl

Active Member
Joined
Oct 23, 2007
Messages
338
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
  2. MacOS
  3. Web
Good Afternoon,
i am working on a project that based on today's date, we would want to have certain default constants be set.
I have a table called tblTerm which has the following fields termID, termDescLong, termDescShort, termDefaultStart, termDefaultEnd which contains what the default values should be.

For example, as today is 9/11/2014 i would use the termID of 1149; however if it was 10/5/2014 i would use the termID 1152

Code:
termID	termDescLong	termDescShort	termDefaultStart	termDefaultEnd
1149	Incoming Fall 2014	FA-14	3/1/2014	9/30/2014
1152	Incoming Spring 2015	SP-15	10/1/2014	2/28/2015

using in my basGlobal module

Code:
Public Const ATBAS_TermID As String = DLookup("[termID]", "tblTerm", "[termDefaultEnd] >=#" & Date() & "# AND [termDefaultStart] <= #" & Date() & "#")


I receive a Compile Error: Constant Expression Required.

Can someone please provide a potential solution to this as I would like to just beable to use the "ATBAS_TermID" variable when I need to insert the termID without recalculating it every time that i need to call it.
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
You cant set a CONSTANT and give it a variable value.
Dont assign them CONST
Just PUBLIC ATBAS_TERMID

then assign at the first form that starts

ATBAS_TERMID = DLOOKUP....

All should work.
 
Upvote 0
That is the perfect answer.

Just a note since the Global was used in the module name. Public and Global are nearly identical in their function, however Global can only be used in standard modules, whereas Public can be used in all contexts (modules, classes, controls, forms etc.) Global comes from older versions of VB and was likely kept for backwards compatibility.
However, there are cases where Global as a naming type can set a variable apart from Public. Not in function, but in using the Search for the code.
Using that in a code module is correct too. Avoid using variables of Public in a Form or Report.
The form load can assign the public variable its value, but the public variable should be outside the form.


 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,559
Members
449,089
Latest member
Motoracer88

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top