In the days of Windows 3.x, if you wanted to save any application settings, such as the window size, toolbars hidden or shown etc. you would have saved that information to an INI file. However, since 32 bit windows (ie Windows 9x), these settings are stored in one location; the registry.

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 regedit.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

Of course, to use the registry you need to be able to retrieve the data you save. To do this you can use the GetSetting function. TheGetSetting function uses the following syntax:

GetSetting AppName, Section, Key

For example, the following code will get the value stored in Font, under DefaultSettings and fill TextBox1 with it (For an example of how to save this value, see above).

' Get the saved value
TextBox1 = GetSetting (App.Title, "Default Settings", "Font")

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