Solved

GetSetting/SaveSetting

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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

632 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