Firing AfterUpdate Event 
Author Message
 Firing AfterUpdate Event

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 ***
--
Peter Schmidt
Ross-on-Wye, UK



Fri, 27 Jul 2007 18:27:04 GMT  
 Firing AfterUpdate Event
Hi Pete,

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

On Mon, 7 Feb 2005 02:27:04 -0800, "Pete"

Quote:

>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 ***

--
John Nurick [Microsoft Access MVP]

Please respond in the newgroup and not by email.



Sat, 28 Jul 2007 06:06:01 GMT  
 Firing AfterUpdate Event
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

Quote:

> Hi Pete,

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

> On Mon, 7 Feb 2005 02:27:04 -0800, "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 ***

> --
> John Nurick [Microsoft Access MVP]

> Please respond in the newgroup and not by email.



Mon, 30 Jul 2007 23:33:10 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. AfterUpdate and LostFocus Events do not fire

2. AfterUpdate on Textbox fires more than once.

3. Listbox - nav to rec by keystroke does not fire AfterUpdate

4. Listbox - nav to rec by keystroke does not fire AfterUpdate

5. Listbox - nav to rec by Alpha does not fire AfterUpdate

6. Form not firing AfterUpdate

7. AfterUpdate of form not firing in a Project

8. AfterUpdate of form not firing in a Project

9. Listbox - nav to rec by keystroke does not fire AfterUpdate

10. Firing events with the worksheet activate event


 
Powered by phpBB® Forum Software © phpBB Group