?
Solved

Using SaveSettings and GetSettings in MS Access

Posted on 2003-10-28
2
Medium Priority
?
872 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 1000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
Windows Explorer let you handle zip folders nearly as any other folder: Copy, move, change, and delete, etc. In VBA you can also handle normal files and folders, but zip folders takes a little more - and that you'll find here.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

839 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