0

Is there a way to store variables in access which retain their data even after access restarts? The idea is that I will log the date and time of when the form was last opened, which will allow me to only show records since it was last opened.

Alex
  • 3,031
  • 6
  • 34
  • 56
  • Any reason why you do not wish to use a table? – Fionnuala Aug 09 '12 at 13:02
  • @Remou I would happily, I'm just not too sure how to go about it. How would I set and get the variables? – Alex Aug 09 '12 at 15:57
  • See http://stackoverflow.com/questions/2338978/ms-access-what-is-a-recordset-in-vba-what-does-it-serve for some ideas. You can also update a table with a query or an sql statement. – Fionnuala Aug 09 '12 at 15:58
  • @Remou Thanks. In the meantime, I found this tutorial: http://accessexperts.net/blog/2011/01/12/multi-session-global-variables/ but I'm getting a 'Run time error: 3021 - Either BOF or EOF is true, or the current record has been deleted. Requested operation requires a current record'. – Alex Aug 09 '12 at 16:03
  • Never-mind, I had to add one record manually before it worked. Thanks for your help. – Alex Aug 09 '12 at 16:18

2 Answers2

2

Since you are inside Access, just create a table to store such information!

dwo
  • 3,576
  • 2
  • 22
  • 39
  • Sort of like a 'Settings' table? I'm not that familiar with access, what code would I use to get and set the data in the table? – Alex Aug 09 '12 at 13:03
0

In case anyone comes looking here for a method to store Permanent Variables (aka Multi-session Variables) without using Access tables. Here is the techique to achieve this.

Crux : Use TextBox DefautlValue to store data.

Dim strForm As String
Dim frm As Form
strForm = "FormName"
DoCmd.OpenForm strForm, acDesign, , , , acHidden
Set frm = Forms(strForm)
frm.Text0.Caption = "Test"
frm.Text0.DefaultValue = 4
Set frm = Nothing
DoCmd.Close acForm, strForm, acSaveYes

Important Note : Form needs to be open in Design view.

Adarsh Madrecha
  • 6,364
  • 11
  • 69
  • 117