One way to work around this is to create a construtor method for the class, something like this.
In a module
'External Constructor Method For CEmployeeRecordsets Class
Public Function EmployeeDatabase() As CEmployeeRecordsets
Set EmployeeDatabase = New CEmployeeRecordsets
EmployeeDatabase.StationName = g_strStationName
'This acts like a passed variable to the class Initialize
If Not EmployeeDatabase.ConnectDatabase(c_sConnection) Then
MsgBox "Database connection failed at the EmployeeDatabase Constructor.", vbInformation, _
"CTI Office Management System Failure !"
End If
End Function
In the class
Private Sub Class_Initialize()
Set m_hDB = New ADODB.Connection
Set m_rsEmployees = New ADODB.Recordset
Set m_rs = New ADODB.Recordset
End Sub
Friend Function ConnectDatabase(ByVal sConnectionString As String) As Boolean
On Error GoTo ErrHnd
m_hDB.ConnectionString = sConnectionString 'Open The Connection
m_hDB.ConnectionTimeout = 5
m_hDB.Mode = adModeRead
m_hDB.Open
m_hDB.Close
GetPeriodData
ConnectDatabase = True
Exit Function
ErrHnd:
MsgBox Err.Number & " " & Err.Description & " Error Generated By " & Err.Source, vbCritical, "Class Error Trap !"
ConnectDatabase = False
End Function
Property Get StationName() As String
StationName = m_strStationName
End Property
Property Let StationName(ByVal sNew As String)
m_strStationName = sNew
End Property
From the form call the constructor
Private Sub Form_Load()
On Error GoTo ErrHnd
Set m_EmpDB = EmployeeDatabase 'Establish DB connection w/Class Initializtion
Exit Sub
ErrHnd:
Form_ErrorHandler "Form Load Event"
Resume Next
End Sub
Hope this helps.
If you choose to battle wits with the witless be prepared to lose.
![[machinegun] [machinegun] [machinegun]](/data/assets/smilies/machinegun.gif)
I don't work for Stars, but I can't even get a "That a Boy" from my boss ![[cheers] [cheers] [cheers]](/data/assets/smilies/cheers.gif)