Use .ini Files. This will be lengthy, but works great, I do it all the time:
In my example I will retreive a tax rate for sake of simplicity, but you can use any value:
First, I open notepad, and add my Section, Key and value:
Example:
[Section]
Key=Value
So for me, it would be:
[Data]
Taxrate=.082
Markuprate=.55
Note: You can have as many sections, keys and values in an .ini as you like. Also, I named my first section "Data", you could name it anything you want
Now I am going to save the file as dbData.ini (make sure you add the .ini when saving)
Now Copy everything between the lines below into a new module: Trust me, it will work.
==============================
Public Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
Public Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
Public Function GetINI(sINIFile As String, sSection As String, sKey As String, sDefault As String) As String
'Purpose: Returns a value FROM an INI File
'GetINI(Path of INI File, Name of section, Name of Key, Default value if not found)
'Example: GetINI("C:\WINNT\ACROREAD.ini", "AdobeViewer", "MaxApp", "0"
Dim sTemp As String * 256
Dim nLength As Integer
sTemp = Space$(256)
nLength = GetPrivateProfileString(sSection, sKey, sDefault, sTemp, 255, sINIFile)
GetINI = Left$(sTemp, nLength)
End Function
Public Sub WriteINI(sINIFile As String, sSection As String, sKey As String, sValue As String)
'Purpose: Writes value TO an INI File
'GetINI(Path of INI File, Name of Section, Name of Key, Value)
'Example: WriteINI("C:\WINNT\ACROREAD.ini", "AdobeViewer", "AntialiasThreshold", "25"
Dim iCounter As Integer
Dim sTemp As String
sTemp = sValue
'Replace any CR/LF characters with spaces
For iCounter = 1 To Len(sValue)
If Mid$(sValue, iCounter, 1) = vbCr Or Mid$(sValue, iCounter, 1) = vbLf Then Mid$(sValue, iCounter) = " "
Next iCounter
iCounter = WritePrivateProfileString(sSection, sKey, sTemp, sINIFile)
End Sub
==============================
OK, now to retrieve the value you use the GetINI function. You can just retrieve the value, or set a variable equal to it, or even set a public variable equal to it on open of your application, then use it throughout, it's up to you.
Dim myVar
myvar = GetINI("C:\My Documents\dbData.ini", "Data", "Taxrate", "0"
The "0" is the value if not found
To write a value out, us the WriteINI function:
WriteINI("C:\My Documents\dbData.ini", "Data", "Taxrate", "YourValue"
This is assuming your dbData.ini file is located in your "My Documents" folder. You could use constants here for paths, as well as the db.Name function stripping off the database name to retrieve the path of the database.
One advantage to this, is that if values change, you can go edit the .ini file, and you NEVER have to touch the database.