Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Storing variables in the registry?

Status
Not open for further replies.

wabtrainer

IS-IT--Management
Feb 4, 2002
66
0
0
GB
HI there.
I would like to store the name of a table that was last accessed by the user, so that when he restarts access, it can be displayed.
I know I have seen this done somewhere before, and I believe it was used by storing it in the Windows registry.
I am sure there is more than one way to skin a cat though!
Any help on this would be great!

Many thanks and Merry Christmas

Wayne


If you want to be a bear:
Be a Grizzly!
 
I do this in Excel VBA but have not tried in Access. I'll give you some code and we both can go off and try it.

Set up some constants:
Code:
Public Const RPTNAME As String = "RSM Power Tools"
Public Const APPNAME As String = "StocksTracker"
Public Const STKSPASS As String = "password"  [red]'Almost anything can be passed[/red]
Public Const STKNAME As String = "Track Stock"
Then call the items from the Registry
Code:
Sub DailySnapshot()
    Dim lastRow As Long, AardvarkAs As Double
    AardvarkAs = GetSetting(STKNAME, APPNAME, "Worth", "")
    Sheets("Snapshot").Select
And finally write new values
Code:
SaveSetting STKNAME, APPNAME, "LastUse", Now()  [red]'Write to Registry[/red]
SaveSetting STKNAME, APPNAME, "Worth", Range("TotCurr") [red]'Write worth to Registry[/red]
This ditty reads my previous Net Worth from the Registry, takes into account the day's changes, and writes back the new values.

Alan

 
I've got to tell you that storing values from Access in your registry can be a very risky proceedure. Be sure to back the registry up before trying this!

The Missinglinq

Richmond, Virginia

There's ALWAYS more than one way to skin a cat!
 
Thanks for that guys!
I am just experimenting with:
SaveSettings and GetSettings.
I will let you know the results when finished


If you want to be a bear:
Be a Grizzly!
 
I am writing just a simple string to the registry using:
SaveSetting "Data Tool", "Parts List Name", "Name", GetSelectedList()
GetSelectedList() is a function I use to fetch the cuurent value which is a simple string such as "PartsA"

Ok I go to the registry and its there. Result!!!

But when I try to retrieve the value using:
selectedlist = GetSetting("Data Tool", "Parts List Name", "Name", "")
SetSelectedList (selectedlist)
Its a blank string?????

Any Ideas?



If you want to be a bear:
Be a Grizzly!
 
Just curious... Why not store the value in a table? What is the advantage of putting it in the registry?

Ken S.
 
Ken,
Its a good point.
As i said earlier, there is always more than one way to skin a cat in this game.
As it is, I tried both methods and got them both to work!
No real advantage really, I had just seen some application a whilw ago where all user settings were stored in the registry and it seemed quite novel at the time (especially as there were several users).

Wayne


If you want to be a bear:
Be a Grizzly!
 
Where ever you decide to store it you will need to consider adding a string for the user name.

Windows has only one registry so depending on where you store the data it may be the last access for the last user of the machine and not necessarily for the current user.

Just and FYI.

Andy Baldwin

"Testing is the most overlooked programming language on the books!"

Ask a great question, get a great answer. Ask a vague question, get a vague answer.
Find out how to get great answers FAQ219-2884.
 
Andy, the SaveSetting instruction store the value in the HKCU hierarchy.
 
Thanks PHV did not realize that. I always store data in db's or ini's. Try never to touch the dadgum registry.


Andy Baldwin

"Testing is the most overlooked programming language on the books!"

Ask a great question, get a great answer. Ask a vague question, get a vague answer.
Find out how to get great answers FAQ219-2884.
 
I usually try to stay out of the Registry. It's cluttered enough already - if the user uninstalls your app will your registry entry be removed?

Keeping such application information in the database or an ini file seems cleaner and simpler to me. If the database needs to be moved, or user gets a new computer, nothing needs to be done to preserve these settings.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top