To utilise the registry, VB provides a simple function called SaveSetting. The SaveSetting function uses the following syntax:
SaveSetting AppName, Section, Key, Value, [Default]
Where AppName is the name of your application, Section is the next folder up and Key is the item your value is stored in.
For example, the following code will save the contents of TextBox1 in the registry. You do not need to know this, but the full path would be (if using Win 98)
HKEY_USERSCurrentUserSoftwareVB and VBA Program SettingsAppNameSectionKey
You can take a look at this by clicking Start | Run... and type C:Windows egedit.exe . Then look in the path above. However, if you want to change anything, you should back up the registry first!
The following code saves the value of TextBox1.Text to the registry:
' Save the value in Text Box 1
SaveSetting App.Title, "Default Settings", "Font", TextBox1.Text
NOTE: this value will be stored in the current users 'section' in the registery. Other users can change this value without affecting other users settings
Comments