Stuart McLachlan
stuart at lexacorp.com.pg
Wed Jan 18 19:59:30 CST 2006
On 18 Jan 2006 at 18:37, Dan Waters wrote: > Hello Everyone, > > I just spent half the day struggling with the movement of a system from one > server to another. The server path is hardcoded in one place in a startup > form. What would have helped me a lot is to have the path in a text file or > ini file external to the database and stored in the same folder. > > Security is not an issue here, just my convenience, as my plans for the day > were pretty much blown up! > > Using a file for information like this sounds like it might be a fairly > typical solution. Does anyone do this or something like it? > Either an INI file or store it in a System table in the FE. Two common approaches to a System Table are: 1.a table with only one record which stores each parameters in a separate field. 2. A table with one record per parameter. Each record consisting of PName, DataType and Value fields. If you use an INI file, you should use the standard Windows INI file format and write/read using API calls: Option Compare Database Option Explicit 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 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 Const cstrIniFilename As String = "MyApp.Ini" ''**************************** '' Write to INI file ''**************************** Public Function WriteIniFileString( _ ByVal Sect As String, _ ByVal Key As String, _ ByVal Value As String) As Boolean Dim intCharsReturned As Integer If Sect = "" Or Key = "" Then MsgBox "Section Or Key To Write Not Specified !!!", _ vbExclamation, "INI" Else WriteIniFileString = WritePrivateProfileString(Sect, _ Key, Value, ApplDir() & "\" & cstrIniFilename) End If End Function '"**************************** '' Read from INI file ''**************************** Public Function ReadIniFileString( _ ByVal Sect As String, _ ByVal Key As String) As String Dim strReturned As String * 128 Dim intSize As Integer Dim intCharsReturned As Integer If Sect = "" Or Key = "" Then MsgBox "Section Or Key To Read Not Specified !!!", _ vbExclamation, "INI" Else strRet = Space$(128) intSize = Len(strRet) intCharsReturned = GetPrivateProfileString(Sect, Key, "", _ strReturned, intSize, ApplDir() & "\" & cstrIniFilename) If intCharsReturned Then ReadIniFileString = Left$(strRet, intCharsReturned) End If End If End Function '"**************************** '' Get the application directory ''**************************** Static Function ApplDir() As String Dim strApplDir As String Dim strTemp As String If strApplDir = "" Then strTemp = DBEngine(0)(0).Name strApplDir = Left$(strTemp, InStrRev(strTemp, "\")) End If ApplDir = strApplDir End Function -- Stuart