Discussion Locked

Access 97 "Memory" Variable

0 helpful
7 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

In Alpha 4 & Foxpro there was a thing called a Memory Variable. Once you set a value it stayed at that value until you changed it, even when the program was shut down.

My Database is for an Annual Drive (Not always the Current year).

On a Utility Menu I want to set or change DriveYear to 2003.
I then want to be able to use that DriveYear Variable in Queries & Reports. This is a general variable not a field in each record.

Anyone out there know how to accomplish this in Access 97??
Thanks for your help.....
Alan
MRA2@mindspring.com

7 replies

by dklippert

The "Access" word is Public Variable/Function/Module
The quick way would be to just set up a table with that on value, otherwise you could research the use of a Public Module that sets the value.

by mra2

I tried that put you cannot seem to change the VAriable from an application form???

Alan

by camcc591

I do something very similar to your Drive Year variable.

Create a table called “t_Data” (names can be adjusted to your liking). Create a field name called “DriveYear.” I do not know how you use your Utility Menu but you can set the DriveYear variable with this code:

Private Sub vbsSetDrvYr(lngDrvYr As Long)
Dim rcdData As Recordset

Set rcdData = CurrentDb.OpenRecordset("t_Data")
With rcdData
.Edit
!DriveYear = lngDrvYr
.Update
.Close
End With

End Sub

In a Visual Basic public module, put the following code:

Public Function IsDrvYr() As Long

IsDrvYr = DLookup("DriveYear", "t_Data", True)

End Function

With this function in place, you can put “IsDrvYr” in the criteria of any query and only match records for the specified year. If you want a report text to display the selected year, use CStr(IsDrvYr) to retrieve the year as a string.

by mra2

I didn't understand part of your answer. Sent you an Email for clarification....

by sl-campbell

In a Module add a public variable to hold the value. When the program starts (use an Auto Macro), set the value to the saved registry value from the last session, and when closing save the value of the variable back to the registry.
You can do thisusing the GetSetting and SaveSetting functions to save the value to the registry.

This discussion is closed to new replies.