Solved

Using SaveSettings and GetSettings in MS Access

Posted on 2003-10-28
2
796 Views
Last Modified: 2008-02-20
Can anybody tell me the syntax for using these commands in Access 2002.
0
Comment
Question by:regodab
2 Comments
 
LVL 5

Expert Comment

by:nickaskew
ID: 9632521
Hi

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

Regards

Nick
0
 
LVL 5

Accepted Solution

by:
joboy earned 250 total points
ID: 9632531
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.
ie.
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.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
HasData 9 37
Open CSV, modify and save as xls from Access 12 19
Simple Excel re-arrange data.  (I can work in access too). 8 50
Export Query data to excel file 14 36
Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
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 …
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

920 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

14 Experts available now in Live!

Get 1:1 Help Now