Variables changing to fields

chrisdd

New member
Local time
Today, 06:25
Joined
Jun 25, 2021
Messages
16
I'm sure there is something very very simple that I'm missing here but I have 2 global variables FDateFrom and FDateTo which contain 2 dates for a search.

I need to output these in a text field - every time I add the name of the variables to the string Access overrides me and changes them to fields???

="Date Range: " & [FDateFrom] & " to " & [FDateTo]

Should be

="Date Range: " & FDateFrom & FDateTo
 
In what context? If you are defining that as the .ControlSource of a text box, you cannot use variables in that context. You have a couple of choices.

Either in the form's .Current event, manually load those variables to the target text field OR create a function that returns the desired values.

Access doesn't recognize variables in the .ControlSource property. (Or in other control properties, either.)

It has to do with the form's controls being part of the Graphic User Interface (GUI) and variables being part of the Applications Program Interface (API) - which are two different spaces.
 
So you are going to have
01/05/202416/05/2024 ? As your DateRange?
 
In what context? If you are defining that as the .ControlSource of a text box, you cannot use variables in that context. You have a couple of choices.

Either in the form's .Current event, manually load those variables to the target text field OR create a function that returns the desired values.

Access doesn't recognize variables in the .ControlSource property. (Or in other control properties, either.)

It has to do with the form's controls being part of the Graphic User Interface (GUI) and variables being part of the Applications Program Interface (API) - which are two different spaces.
Many thanks for this - working now!
 
Note that for most uses dates have to be surrounded by ## characters. Also some usages will treat the dates as US dates.

So "between #1/5/24# and #31/5/24#" can end up getting treated as between Jan 5th and May 31st. It's worth testing to make sure it does what you want.
 
Note that for most uses dates have to be surrounded by ## characters. Also some usages will treat the dates as US dates.

So "between #1/5/24# and #31/5/24#" can end up getting treated as between Jan 5th and May 31st. It's worth testing to make sure it does what you want.
Why I alway, when specifying dates, using #1/MAY/2024# and #31/May/2024# in the example above.

Blame it all on Gates and Allen when they invented MS-DOS in days of yore, and IBM adopted it to save money. At least in those days when we had the choice of CP/M (vastly superior in my opinion) you could only use US for format dates on CP/M - not great for a Brit but at least we knew where we stood.
 
Just in case it might be useful, look up TempVars too. I think you can use them directly in Control Sources without using code.
 
TempVars can be referenced in ControlSource and queries and macros and they retain values even when unhandled runtime error is triggered (globals do not).

Does require code (macro or VBA) to establish and populate.
 

Users who are viewing this thread

Back
Top Bottom