G
Guest
i have a main form and 6 subforms. i have an audit trail code which works
fine with all six subforms and a main form except when i perform Del
operation on subform.let me give you a situation how it works.
On main Form i Have field Atype & Rtype., based on which one subform opens
in new window.
let say Atype = B & Rtype= S
On Rtype OnChange event Subform B_S opens
then on B-S i perform Del & on DelConfirm it closes automatically and n base
on what Rtype was changed to corresponding subform opens up but when i enter
value on the subform n move my focus back to main form its gives me MSG
"INVALID OBJECT OR OBJECT NO LONGER SET" but if i Close everthing and open
again it works fine but i Dont want that msg at all...because it will confuse
users.
i know its a long question but i shall appreciate any help.
Thank You.
Here is CODE which i am using
Public Function AuditTrail1(PsubformName, PLevel, Optional Psub1)
On Error GoTo err_AuditTrail1
Dim MyForm As Form, C As Control
Dim rs As Recordset
Dim db As Database
Dim bOK As Boolean
Set db = CurrentDb
Set rs = db.OpenRecordset("tblAudit")
bOK = False
DoCmd.SetWarnings False
Select Case PLevel
Case 1: Set MyForm = Screen.ActiveForm
Case 2: Set MyForm = Screen.ActiveForm(PsubformName).Form
Case 3: Set MyForm = Screen.ActiveForm(Psub1).Form(PsubformName).Form
End Select
For Each C In MyForm.Controls
If TypeOf C Is TextBox Or TypeOf C Is ComboBox Then
If C.Value <> C.OldValue Or IsNull(C.OldValue) Then
If Not IsNull(C.Value) Then
rs.AddNew
rs!Comments = "CHECKING"
rs!TableChanged = MyForm.RecordSource
rs!FieldChanged = C.Name
rs!FieldChangedFrom = C.OldValue
rs!FieldChangedTo = C.Value
rs!User = VBA.Interaction.Environ("USERNAME")
rs!DateofHit = Now
rs.Update
rs.Close
db.Close
End If
End If
End If
Next C
AuditTrail1 = bOK
exit_AuditTrail1:
DoCmd.SetWarnings True
Exit Function
err_AuditTrail1:
MsgBox Err.Description
Resume exit_AuditTrail1
End Function
fine with all six subforms and a main form except when i perform Del
operation on subform.let me give you a situation how it works.
On main Form i Have field Atype & Rtype., based on which one subform opens
in new window.
let say Atype = B & Rtype= S
On Rtype OnChange event Subform B_S opens
then on B-S i perform Del & on DelConfirm it closes automatically and n base
on what Rtype was changed to corresponding subform opens up but when i enter
value on the subform n move my focus back to main form its gives me MSG
"INVALID OBJECT OR OBJECT NO LONGER SET" but if i Close everthing and open
again it works fine but i Dont want that msg at all...because it will confuse
users.
i know its a long question but i shall appreciate any help.
Thank You.
Here is CODE which i am using
Public Function AuditTrail1(PsubformName, PLevel, Optional Psub1)
On Error GoTo err_AuditTrail1
Dim MyForm As Form, C As Control
Dim rs As Recordset
Dim db As Database
Dim bOK As Boolean
Set db = CurrentDb
Set rs = db.OpenRecordset("tblAudit")
bOK = False
DoCmd.SetWarnings False
Select Case PLevel
Case 1: Set MyForm = Screen.ActiveForm
Case 2: Set MyForm = Screen.ActiveForm(PsubformName).Form
Case 3: Set MyForm = Screen.ActiveForm(Psub1).Form(PsubformName).Form
End Select
For Each C In MyForm.Controls
If TypeOf C Is TextBox Or TypeOf C Is ComboBox Then
If C.Value <> C.OldValue Or IsNull(C.OldValue) Then
If Not IsNull(C.Value) Then
rs.AddNew
rs!Comments = "CHECKING"
rs!TableChanged = MyForm.RecordSource
rs!FieldChanged = C.Name
rs!FieldChangedFrom = C.OldValue
rs!FieldChangedTo = C.Value
rs!User = VBA.Interaction.Environ("USERNAME")
rs!DateofHit = Now
rs.Update
rs.Close
db.Close
End If
End If
End If
Next C
AuditTrail1 = bOK
exit_AuditTrail1:
DoCmd.SetWarnings True
Exit Function
err_AuditTrail1:
MsgBox Err.Description
Resume exit_AuditTrail1
End Function