Solved

GetSetting/SaveSetting

Posted on 2006-11-03
5
929 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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
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…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
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.

770 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