?
Solved

Using SaveSettings and GetSettings in MS Access

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
Suggested Courses

752 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