Solved

GetSetting/SaveSetting

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

706 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now