GK in the UK
Registered User.
- Local time
- Today, 21:45
- Joined
- Dec 20, 2017
- Messages
- 274
Have I missed something glaringly obvious ? My WithEvents routines aren't working.
I want to act on AfterInsert of a child form.
I can get a response on Dirty, but when I code for AfterInsert I get Error 2465 Application or Object Error
Here's my code:
Code to open the child form and set the event:
I can uncomment the OnAfterInset code, comment OnDirty and it breaks.
Why is it only working with the Dirty event (obviously only one set of the test code is uncommented) ?
The child form opens but I immediately get the error message.
I want to act on AfterInsert of a child form.
I can get a response on Dirty, but when I code for AfterInsert I get Error 2465 Application or Object Error
Here's my code:
Code:
Private WithEvents PurchDaybookDocRef As Access.TextBox
Private WithEvents PurchDaybookAccRef As Access.TextBox
Private WithEvents ChildForm As Access.Form
' ================================================================================
' Remote Events Follow:
' ================================================================================
Private Sub PurchDaybookDocRef_Click()
'MsgBox ("PurchDaybookDocRef_Click !")
' Call the View button
cmdView_Click
End Sub
Private Sub PurchDaybookAccRef_Click()
' Open the customer or supplier record
MsgBox ("PurchDaybookAccRef_Click !")
End Sub
''' CAN'T MAKE THIS WORK
'Private Sub ChildForm_AfterInsert() ' BROKEN
'' Code to run on the AfterInsert event of frmInvoice
'' We've added a new invoice document
'MsgBox ("About to requery")
'RequeryIndex
'End Sub
'' CAN'T MAKE THIS WORK
'Private Sub ChildForm_BeforeUpdate(Cancel As Integer) ' BROKEN
'' Code to run on the BeforfeUpdate event of frmInvoice
'' We've added a new invoice document
'MsgBox ("About to requery")
'RequeryIndex
'End Sub
'
Private Sub ChildForm_Dirty(Cancel As Integer) ' WORKS
' Code to run on the AfterInsert event of frmInvoice
' We've added a new invoice document
MsgBox ("About to requery")
RequeryIndex
End Sub
Code to open the child form and set the event:
Code:
Private Sub cmdView_Click()
' view an existing document in the index
Dim strFormName As String
' txtDocType is hidden text on the form, put there from each tab control
' when it is clicked, it's the name of the current tab sub form
' Form name comes from tblDocTypes via strFormName
' txtTransHeaderID also comes from the currently highlighted document
strFormName = fFormName(Me.txtDocType) ' eg 'frmInvoice'
' Open the relevant form according to the document type that we clicked on
DoCmd.OpenForm strFormName, _
WhereCondition:="TransHeaderID = " & Me.txtTransHeaderID, _
DataMode:=acFormReadOnly, _
OpenArgs:=Me.txtDocType & "|" & "Editable"
' Set the event handler, we can't do this until the form is loaded
' This code executes as soon as the child form is loaded
Set ChildForm = Forms(strFormName).Form ' OK
ChildForm.OnDirty = "[Event Procedure]" ' WORKS
'ChildForm.OnBeforeUpdate = "[Event Procedure]" ' Error 2465 app or object error
'ChildForm.OnAfterInsert = "[Event Procedure]" ' Error 2465 app or object error
End Sub ' cmdView_Click
Why is it only working with the Dirty event (obviously only one set of the test code is uncommented) ?
The child form opens but I immediately get the error message.