
Read/Write INI Files w/Access 7.0
Quote:
>I need to read/write INI files from Access 7.0. I had no problem doing it
>with Access 2.0 and now things won't work correctly in 7.0. I tried
>changing my declarations to use GetPrivateProfileStringA but it doesn't
>work. The WritePrivateProfileStringA works great! Could someone please
>direct me to some info on how to do this with Access 7.0?
Here are the Declares I use in VB4, they should be the same for Access
7 & 8:
Declare Function mtkGetPrivateProfileString _
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 mtkGetPrivateProfileSection _
Lib "kernel32" Alias "GetPrivateProfileSectionA" ( _
ByVal lpAppName As String, _
ByVal lpReturnedString As String, _
ByVal nSize As Long, _
ByVal lpFileName As String) _
As Long
Declare Function mtkGetPrivateProfileInt _
Lib "kernel32" Alias "GetPrivateProfileIntA" ( _
ByVal lpApplicationName As String, _
ByVal lpKeyName As String, _
ByVal nDefault As Long, _
ByVal lpFileName As String) _
As Long
Declare Function mtkWritePrivateProfileSection _
Lib "kernel32" Alias "WritePrivateProfileSectionA" ( _
ByVal lpAppName As String, _
ByVal lpString As String, _
ByVal lpFileName As String) _
As Long
Declare Function mtkWritePrivateProfileString _
Lib "kernel32" Alias "WritePrivateProfileStringA" ( _
ByVal lpApplicationName As String, _
ByVal lpKeyName As Any, _
ByVal lpString As Any, _
ByVal lpFileName As String) _
As Long
Public Function mtkWriteIni(strSection As String, strKey As String,
strEntry As String, strIni As String) As Boolean
Dim lngVal As Long
On Error GoTo WriteIni_Err
lngVal = mtkWritePrivateProfileString( _
lpApplicationName:=strSection, _
lpKeyName:=strKey, _
lpString:=strEntry, _
lpFileName:=strIni)
mtkWriteIni = True
WriteIni_Exit:
Exit Function
WriteIni_Err:
If Err.Number <> 0 Then
mtkWriteIni = False
End If
Resume WriteIni_Exit
End Function
Public Function mtkReadIni(strSection As String, strKey As String,
strIni As String) As String
Dim lngVal As Long, strBuf As String * 256
lngVal = mtkGetPrivateProfileString( _
lpApplicationName:=strSection, _
lpKeyName:=strKey, _
lpDefault:="", _
lpReturnedString:=strBuf, _
nSize:=256, _
lpFileName:=strIni)
If lngVal > 0 Then
mtkReadIni = Left(strBuf, lngVal)
Else
mtkReadIni = ""
End If
End Function
...Joe Maki
MT Kupp & Associates