Solved

GetSetting/SaveSetting

Posted on 2006-11-03
5
930 Views
Last Modified: 2012-05-05
Hi all

I'm trying to use GetSetting and SaveSetting to retreive and store data.  I'm having an issue with GetSetting.

WHat I'm trying to do is allow users to save some options from my database to the registry.  I want to be able to have some default settings before they ever open the database and then I want them to be able to change them and store them.  I was thinking of creating all the registry keys I need and then have them imported into the user's registry automatically when they download my database from our local intranet.  Getting the keys out there isnt an issue, but I wanted to give some background.

So far, as a test on my PC, I've created a the following registry entries...
-------------------------------------------------------------------------------------------------------------
[HKEY_CURRENT_USER\Software\VB and VBA Program Settings\AWG2007]

[HKEY_CURRENT_USER\Software\VB and VBA Program Settings\AWG2007\Application]
"AppName"="AuditWizard GUI 2007"
"LocalVersion"="3.3.0.2"
"LastRevision"="10/23/2006"
"Maximize"="-1"
"ShowToolsMenu"="0"
"ScreenResolution"=""

[HKEY_CURRENT_USER\Software\VB and VBA Program Settings\AWG2007\Options]
"AutoUpdate_On/Off"="0"
"AutoUpdate_Type"=""
"Location_Database"=""
"Location_Save"=""
"Location_Backup"=""
"Filter_InstalledSoftware"="0"
"UpdateCountsEnabled"="0"
"UpdateCountsTime"=""
"RefreshDatabaseEnabled"="0"
"RefreshDatabaseTime"=""
"ShowTimers"="0"
-------------------------------------------------------------------------------------------------------------

I have a form (frmOptions) with controls for each registry key.  The first control I've been working with as a test has been txtDBLocation.  This textbox will show the value of the key "Location_Database".  The user can also enter text into this textbox to update the registry key value.  What I've done to test this is set the following code in the OnOpen event of the frmOptions form.
-------------------------
Private Sub Form_Open(Cancel As Integer)
     Dim strDBLOCdef As String
     strDefault = Environ("userprofile") & "\desktop\"
     Me.txtDBLocation.Value = GetSetting("AWG2007", "Options", "Location_Database", strDefault)
End Sub
-------------------------
This work fine if there is a value stored in the Location_Database key, but if the value is blank nothing gets put into the textbox (no matter if set a default value in the GetSetting string).  Also, instead of using the Environ string I tried a simple "test" as the default value and this didnt work either....

Any thoughts on this?
Thanks
0
Comment
Question by:edh-home
  • 2
5 Comments
 

Author Comment

by:edh-home
ID: 17867879
correction to above: Dim strDBLOCdef As String is actually strDefault
0
 
LVL 44

Accepted Solution

by:
Arthur_Wood earned 500 total points
ID: 17867922
try it this way:

Private Sub Form_Open(Cancel As Integer)
     Dim strDBLOCdef As String
     Dim strSetting
     strDefault = Environ("userprofile") & "\desktop\"

     ' the default value (strDefault) is only returned in the case where the Setting for Location_Database is not present at all in the registry
     strSetting = GetSetting("AWG2007", "Options", "Location_Database", strDefault)

     If strSetting = "" Then  ' this tests for the entry Location_Database being present, but holds a blank
              txtDBLocation.Value  = strDefault
     Else
             txtDBLocation.Value  = strSetting
     End If
End Sub


AW
0
 

Author Comment

by:edh-home
ID: 17869521
That works, but I thought the whole point of the default value was so that you didn't have to do an IF statement.  Am I wrong?
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
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…

790 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