I am experimenting to create a 3-tier vba app. User can use it to search employee data and display on it. But when I click to open the form, a dialogue box appears with the following error:
The expression On Load you entered as the event property setting produced the following error:
*****************************************************************************
The detail:
This error occurs when an event has failed to run because Microsoft Office Access cannot evaluate the location of the logic for the event. For example, if the OnOpen property of a form is set to =[Field], this error occurs because Access expects a macro or event name to run when the event is fired.
*****************************************************************************
But I don't understand what "For example, if the OnOpen property of a form is set to =[Field],.." means and referring to. What's wrong with the code in On Load? My class declaration has problem or some place else?
I have included part of the code as follow. I have it stuck for a month. Please advise me. Thanks very much.
----------------------------------------------------------
Private Sub Form_Load()
On Error GoTo HandleError
Set objEmp = New clsEmp
Set rsEmp = New ADODB.Recordset
Call LoadRecords
MsgBox "Form Load"
Exit Sub
HandleError:
GeneralErrorHandler Err.Number, Err.Description, PROJECTS_EMP, "Form_Load"
Exit Sub
End Sub
----------------------------------------------------------
Sub LoadRecords()
On Error GoTo HandleError
MsgBox "Load record"
'populate the main recordset
Set rsEmp = objEmp.RetrieveEmp
'if the recordset is empty
If rsEmp.BOF And rsEmp.EOF Then
Exit Sub
Else
'populate the object with values in the recordset
objEmp.PopulatePropertiesFromRecordset rsEmp
'populate the controls on the form with the current record
Call PopulateListbox
End If
Exit Sub
HandleError:
GeneralErrorHandler Err.Number, Err.Description, PROJECTS_EMP, "LoadRecords"
Exit Sub
End Sub
----------------------------------------------------------
Sub PopulateListbox()
On Error GoTo HandleError
'populate the listbox
Set rsEmp = New ADODB.Recordset
Set rsEmp = objEmp.RetrieveEmp(objEmp.EmpID)
PopulateListBoxFromRecordset Me.lstEmp, rsEmp, 1
rsEmp.Close
HandleError:
GeneralErrorHandler Err.Number, Err.Description, PROJECTS_EMP, "PopulateListBox"
Exit Sub
End Sub
The expression On Load you entered as the event property setting produced the following error:
*****************************************************************************
The detail:
This error occurs when an event has failed to run because Microsoft Office Access cannot evaluate the location of the logic for the event. For example, if the OnOpen property of a form is set to =[Field], this error occurs because Access expects a macro or event name to run when the event is fired.
*****************************************************************************
But I don't understand what "For example, if the OnOpen property of a form is set to =[Field],.." means and referring to. What's wrong with the code in On Load? My class declaration has problem or some place else?
I have included part of the code as follow. I have it stuck for a month. Please advise me. Thanks very much.
----------------------------------------------------------
Private Sub Form_Load()
On Error GoTo HandleError
Set objEmp = New clsEmp
Set rsEmp = New ADODB.Recordset
Call LoadRecords
MsgBox "Form Load"
Exit Sub
HandleError:
GeneralErrorHandler Err.Number, Err.Description, PROJECTS_EMP, "Form_Load"
Exit Sub
End Sub
----------------------------------------------------------
Sub LoadRecords()
On Error GoTo HandleError
MsgBox "Load record"
'populate the main recordset
Set rsEmp = objEmp.RetrieveEmp
'if the recordset is empty
If rsEmp.BOF And rsEmp.EOF Then
Exit Sub
Else
'populate the object with values in the recordset
objEmp.PopulatePropertiesFromRecordset rsEmp
'populate the controls on the form with the current record
Call PopulateListbox
End If
Exit Sub
HandleError:
GeneralErrorHandler Err.Number, Err.Description, PROJECTS_EMP, "LoadRecords"
Exit Sub
End Sub
----------------------------------------------------------
Sub PopulateListbox()
On Error GoTo HandleError
'populate the listbox
Set rsEmp = New ADODB.Recordset
Set rsEmp = objEmp.RetrieveEmp(objEmp.EmpID)
PopulateListBoxFromRecordset Me.lstEmp, rsEmp, 1
rsEmp.Close
HandleError:
GeneralErrorHandler Err.Number, Err.Description, PROJECTS_EMP, "PopulateListBox"
Exit Sub
End Sub