READING an INI file while opening access (1 Viewer)

thick_guy_9

New member
Local time
Today, 13:39
Joined
Jun 21, 2009
Messages
7
Hello all
I guess I have multiple questions. Rather than receive multiple conflicting answers I have decided to put it in one thread.

I have set Access to display a Form when the user opens the database.
I want to read all the values in an INI file. To do this, I want to read all values in the FORM's ON LOAD method.

To read the INI file I want to use the WIN32 API GetPrivateProfileString

QUESTION: When I declare the below function in GENERAL DECLARATIONS and open the form, I get an error that Declare Statements, fixed length strings, arrays and constants cannot be Public members of object modules.

GENERAL DECLARATIONS
-----------------------
Option Compare Database
Option Explicit
Private Const iStrLen As Integer = 200 ' a CONST - could be cause of error
' Declare could also be cause of error
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

---------------------------------------------------
Private Sub Form_Load()
MsgBox "boo"
' here read INI file
Dim sKey1 As String
Dim sKey2 As String
Dim sKey3 As String
Dim sVal1 As String
Dim sVal2 As String
Dim sVal3 As String
Dim sINIFileName As String
Dim sSecName As String
Dim sRetVal As String
Dim lRetLen As Long

Dim bGotINIVal As Boolean

sRetVal = Space$(iStrLen)
MsgBox "boo boo boo"

sINIFileName = CurrentProject.Path & "\" & "XYZ.INI"
Debug.Print sINIFileName
sSecName = "INITVAL"
sKey1 = "Key1"
lRetLen = 0
'lRetLen = GetPrivateProfileString(sSecName, sKey1, "", sRetVal, Len(sRetVal), sINIFileName)

If lRetLen <> 0 Then
'trim the result here
sVal1 = Trim$(Left$(sRetVal, lRetLen))
bGotINIVal = True
Else
bGotINIVal = False
End If


End Sub


================================================
So I will be thankful for any help and advise.
Thanks in advance
 

SOS

Registered Lunatic
Local time
Today, 04:39
Joined
Aug 27, 2008
Messages
3,517
This part:
Code:
Private Const iStrLen As Integer = 200 ' a CONST - could be cause of error
' Declare could also be cause of error
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
Needs to be in a STANDARD module, not in a form or report module.
 

thick_guy_9

New member
Local time
Today, 13:39
Joined
Jun 21, 2009
Messages
7
Thank you!!
 

Users who are viewing this thread

Top Bottom