Firing AfterUpdate Event

P

Pete

I have written a simple form containing a calendar control, that can be used
when entering date values. It is called by double-clicking on the control. It
works really well as it uses the screen.active control to pass the reference
to the control so is not hard coded in any way and works whether the control
is on a form, subform or nested subform.

The problem I have is that as I am changing the value of the control
programmatically if it has an AfterUpdate event it will not fire. I can
detect if there is an event using:

If objControl.AfterUpdate = "[Event Procedure]"

What I can't work out is how to fire this event - I am trying to avoid
hard-coding form/object names so that the calendar form can be used
throughout my application (and indeed other databases).


'*** START OF CODE ***
Option Compare Database
Option Explicit
Dim objControl As Object

Private Sub cmdClose_Click()
DoCmd.Close
End Sub

Private Sub cmdCloseandCopy_Click()
axCalendar_DblClick
End Sub

Private Sub axCalendar_DblClick()
objControl = Me.axCalendar.Value
Set objControl = Nothing
DoCmd.Close
End Sub

Private Sub Form_Load()
'*** Set Calendar to Control's Current Value or Current Date if Blank ***
Me.axCalendar.Value = Screen.ActiveControl.Value
If IsNull(Screen.ActiveControl.Value) Then Me.axCalendar = Date
Set objControl = Screen.ActiveControl
End Sub

'*** END OF CODE ***
 
J

John Nurick

Hi Pete,

If you're using a recent version of Access (I can't remember which this
applies to), check out the CallByName() function.

I have written a simple form containing a calendar control, that can be used
when entering date values. It is called by double-clicking on the control. It
works really well as it uses the screen.active control to pass the reference
to the control so is not hard coded in any way and works whether the control
is on a form, subform or nested subform.

The problem I have is that as I am changing the value of the control
programmatically if it has an AfterUpdate event it will not fire. I can
detect if there is an event using:

If objControl.AfterUpdate = "[Event Procedure]"

What I can't work out is how to fire this event - I am trying to avoid
hard-coding form/object names so that the calendar form can be used
throughout my application (and indeed other databases).


'*** START OF CODE ***
Option Compare Database
Option Explicit
Dim objControl As Object

Private Sub cmdClose_Click()
DoCmd.Close
End Sub

Private Sub cmdCloseandCopy_Click()
axCalendar_DblClick
End Sub

Private Sub axCalendar_DblClick()
objControl = Me.axCalendar.Value
Set objControl = Nothing
DoCmd.Close
End Sub

Private Sub Form_Load()
'*** Set Calendar to Control's Current Value or Current Date if Blank ***
Me.axCalendar.Value = Screen.ActiveControl.Value
If IsNull(Screen.ActiveControl.Value) Then Me.axCalendar = Date
Set objControl = Screen.ActiveControl
End Sub

'*** END OF CODE ***
 
P

Pete

Hi John,

Thanks for you reply. I had not come across this function before. Took a
while to work out the syntax - you need to make the AfterUpdate routine a
Public Sub. The following code then works:

Private Sub axCalendar_DblClick()
objControl.Value = Me.axCalendar.Value
If objControl.AfterUpdate = "[Event Procedure]" Then
CallByName objControl.Parent, objControl.Name & "_AfterUpdate",
VbMethod
End If
Set objControl = Nothing
DoCmd.Close
End Sub

Thanks for pointing me in the right direction. This function is very useful
and it means that my calendar form will work in any of my databases unchanged!

Pete

John Nurick said:
Hi Pete,

If you're using a recent version of Access (I can't remember which this
applies to), check out the CallByName() function.

I have written a simple form containing a calendar control, that can be used
when entering date values. It is called by double-clicking on the control. It
works really well as it uses the screen.active control to pass the reference
to the control so is not hard coded in any way and works whether the control
is on a form, subform or nested subform.

The problem I have is that as I am changing the value of the control
programmatically if it has an AfterUpdate event it will not fire. I can
detect if there is an event using:

If objControl.AfterUpdate = "[Event Procedure]"

What I can't work out is how to fire this event - I am trying to avoid
hard-coding form/object names so that the calendar form can be used
throughout my application (and indeed other databases).


'*** START OF CODE ***
Option Compare Database
Option Explicit
Dim objControl As Object

Private Sub cmdClose_Click()
DoCmd.Close
End Sub

Private Sub cmdCloseandCopy_Click()
axCalendar_DblClick
End Sub

Private Sub axCalendar_DblClick()
objControl = Me.axCalendar.Value
Set objControl = Nothing
DoCmd.Close
End Sub

Private Sub Form_Load()
'*** Set Calendar to Control's Current Value or Current Date if Blank ***
Me.axCalendar.Value = Screen.ActiveControl.Value
If IsNull(Screen.ActiveControl.Value) Then Me.axCalendar = Date
Set objControl = Screen.ActiveControl
End Sub

'*** END OF CODE ***
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top