Thanks Rod,
The back end databases are located on a server in a central location and all settings I have implemented to date are overall settings affecting all users. I did create the settings table at the server level with all fields mentioned above.
The functions to read settings were custom and they worked but were slow using both a DLookup, allen browns ELookup, and via a queried recordset so I ended up using the solution below, which is very fast.
Upon database startup the entire settings table is opened in a ado recordset and then put into a multi-dimension array via a custom function (error trapping not implemented yet. Get records is a custom multi-purpose function that can both read records into memory and also populate unbound form fields based on control names and tags. In this case GetRecords only reads to a recordset in memory. SettingsArr, SettingsRowNum & SettingsColNum are globals):
Code:
Public Function LoadSettings() As Boolean
LoadSettings = False
If GetRecords("tbl_dbSettings") Then
If Not rst.EOF Then
SettingsArr = rst.GetRows(rst.RecordCount)
SettingsRowNum = UBound(SettingsArr, 2)
SettingsColNum = UBound(SettingsArr, 1)
LoadSettings = True
End If
End If
End Function
I changed the read settings function from one that queried a single record and returned results to one that loops through the array and returns the requested value. This method works instantly and there is no more network lag when looking up settings.
Code:
Public Function ReadSetting(sName As String, sVar As sVariant) As Variant
Dim sCol As Integer
Dim rCounter As Integer
Dim tmpVal As Variant
sCol = sVar
For rCounter = 0 To SettingsRowNum
If sName = SettingsArr(0, rCounter) Then
tmpVal = Nz(SettingsArr(sCol, rCounter), "")
If sVar = 1 Then
ReadSetting = CBool(tmpVal) 'True/False On/Off
Exit Function
ElseIf sVar = 2 Then
ReadSetting = CInt(Nz(tmpVal, 1)) 'Security Level 1-3
Exit Function
ElseIf sVar = 3 Then
ReadSetting = CStr(Nz(tmpVal, "")) 'Custom Setting Value(s)
Exit Function
ElseIf sVar = 4 Then
ReadSetting = CStr(Nz(tmpVal, "")) 'Setting Description
Exit Function
End If
End If
Next
End Function
sVariant is defined as:
Code:
Enum sVariant
Value = 1
Security = 2
Custom = 3
Description = 4
End Enum
There's more work I need to do such as adding error trapping (I have custom functions for this as well that auto-report bugs) and adding a function to check and reload settings if an unhandled exception causes them and the globals to disappear.