Using SaveSettings and GetSettings in MS Access

Posted on 2003-10-28
Last Modified: 2008-02-20
Can anybody tell me the syntax for using these commands in Access 2002.
Question by:regodab

Expert Comment

Comment Utility

Lets say you have a form (frmTest) that needs to remember the value of a text field (tbTest) when it is closed, so that it can retrieve that value and fill the form in again (presuming the data isn't stored within a table..)

' This saves the contents of the field 'tbText' into a registry entry called 'ValueInTextBoxWeNeed'
Private Sub Form_Close()
    SaveSetting "MyExampleDB", "frmTest", "ValueInTextBoxWeNeed", Me.tbText
End Sub

' This retrieves the registry entry called 'ValueInTextBoxWeNeed' and places its value into the control 'tbText', note the double quotes at the end of GetSetting, this is the default setting that should be used if the registry does not contain an entry called 'ValueInTextBoxWeNeed'
Private Sub Form_Load()
    Me.tbText = GetSetting("MyExampleDB", "frmTest", "ValueInTextBoxWeNeed", "")
End Sub



Accepted Solution

joboy earned 250 total points
Comment Utility
The syntax should be something like:

SaveSetting "YourApplicationName","Settings","LastShutdown",now()

The First parameter describes your application name.
The second the general nature/group of the information you're going to save.
The third parameter describes specifically the peice of information that is going to be saved
The final parameter is the value of the information to be saved.

Thus the above example will store the LastShutdown time of your application, inside the Settings group.
It will create the following key in your registry.
HKEY_CURRENT_USER\Software\VB and VBA Program Settings\YourApplicationName\Settings\LastShutDown  = "28/10/03 09:37:40"

This information can then be read back using the GetSetting function

Dim strDate as String
Dim dtmDate As Date

strDate = GetSetting("YourApplicationName","Settings","LastShutdown")
'strDate now holds "28/10/03 09:37:40"
'Not GetSetting always returns a string value

dtmDate=CDate(strDate) 'Convert the string date back to a real date.

The GetSetting function also has a fourth parameter call Default. If this is specified then the value in Default is used if an entry in the registry cannot be found.
strDate = GetSetting("YourApplicationName","Settings","LastStartUp",now())

Note we are looking for the LastStartUp value, as we haven't created this registry entry yet (using SaveSetting) it will return the current Date and Time.

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now