Solved

Using SaveSettings and GetSettings in MS Access

Posted on 2003-10-28
2
828 Views
Last Modified: 2008-02-20
Can anybody tell me the syntax for using these commands in Access 2002.
0
Comment
Question by:regodab
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

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

Suggested Solutions

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

734 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