Link to home
Start Free TrialLog in
Avatar of Sandra Smith
Sandra SmithFlag for United States of America

asked on

Using Calendar not firing After Update event

I have an ACCESS 2003 form that uses a calendar to populate a text box.  But when the user uses the Calendar, it does not fire the After Update event and thus does not capture any of error trapping - such as is the date before another text box's date.  is there anotheir event I should be using?
Avatar of DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
Flag of United States of America image

Normally, you do validation in a Before Update event ... does the calendar have that?
What calendar are you using ?

mx
Avatar of Sandra Smith

ASKER

I am using a calendar program obtain through EE that was developed by Stephen Lebans.  Let me try the Before statement and get back to you.
Nope, did not get fired apparently even in the Before update event.
This is the descriptor:
'DEVELOPED AND TESTED UNDER MICROSOFT ACCESS 97 VBA
' There is a seperate A2K or higher version required because
' A97 does not support AddressOf.
' That is the only difference between the A97 and the A2K versions.
'
'Copyright: Stephen Lebans - Lebans Holdings 1999 Ltd.
'           Pedro Gil
'           Please feel free to use this code within your own
'           projects whether they are private or commercial applications
'           without obligation.
'           This code may not be resold by itself or as part of a collection.
'
'Name:      clsMonthCal
'
'Version:   2.05
'
'Purpose:
'           To allow for the selection of a Date or Dates using the standard
'           Windows Month Calendar control without having to use the ActiveX control.

'Authors:   Stephen Lebans
'           Pedro Gil
Will take a look at that one ... in a moment.  Most of these calendars populate a text box, which should cause the OnChange event to trigger in the text box ...

In the meantime ...

This is my favorite Lebans because no form is required.  
Calendar (with loads of cool stuff) is created on the fly each time:
http://www.lebans.com/monthcalendar.htm

Calendar Month View
http://www.mvps.org/access/forms/frm0052.htm

Mini Calendar
http://www.mvps.org/access/forms/frm0050.htm

Popup Calendar
http://allenbrowne.com/ser-51.html

mx
Actually, the first link you have is the one I used (i have it bookmarked already).  
ok .... yes I see ... it's the same.

<But when the user uses the Calendar, it does not fire the After Update event>

the afterupdate event of the textbox will not happen if you are populating the textbox from codes.
so, to make use of the afterupdate event, you need to call the afterUpdate event after populating the textbox from the calendar click event

   textboxName_afterUpdate

Put this code in the On Change Event of each text box you are using the calendar on:

Private Sub txtMyDate_Change()
Msgbox "Calendar Date Entered"
End Sub

I just tested this and that even will trigger. Then you can do validation.

mx
So ....

Private Sub txtMyDate_Change()
    ' Your validation code here
End Sub

The MsgBox was just to show it being triggered.  The reason this event triggers is because the .Text property of the text box is changed, which fortunately ... triggers the On Change event.

mx
Ok, still won't pick up when useding the calendar.  However, if I type in the text box, then the message does appear.  It seems to expected a physical typing in the box.
Ok, I got it to work using the Lost Focus even.  Dang, that was like pulling teeth!
Cap, there is no Calendar click event as the calendar is virtual, created in code, not being resident on a form.
Well ... it definitely worked for me ...

mx
<Cap, there is no Calendar click event>

look for the code that populate the textbox with date, then call the textbox afterupdate event next to it.
Let me clean out the database of proprietary information and post.
you may have to make the textbox afterupdate event public, instead of private i.e.,

public textbox_afterupdate()



end sub


then you can call it
        Forms!NameOfForm.textbox_afterupdate
ssmith94015:
If you are using the Lebans calendar, ... then what I posted should work for you.  And this is exactly what done in the past with this calendar.  I highly recommend *not* trying to modify the Lebans code.

mx
The On Change event will trigger as soon as it's populated with text (date). The AU event will not trigger until you exit the combo box.

mx
I believe all of the comments, I am attaching the database itself.  I did not change the calendar code, it worked so there was no reason.  The form I am talking about is the "New Task" form opened from the main menu (after the splash). It should be the first button in the middle column of buttons.  The two fields are Due Date and Assign Date, the Due Date is the only one that actually uses the calendar.  The Project Date next to the project selection drop-down is one of the dates against which the Task Due Date is checked, as well as checking that the due date is later than the Assigned date.
TrackingShell.mdb
Just an fyi ... in the future
1 Compact & Repair the db
2 Zip it up before upload.  This db is 21 Mega Bytes.

mx
Well, in your db, it's not triggering the On Change - no clue why.  But ... the Lost Focus does trigger of course, so you can do your validation there.

mx
OK ... I found the issue.

Change this:

blRet = ShowMonthCalendar(mc, dtStart, dtEnd)
If blRet = True Then
    Me.txtDueDate= dtStart
Else
    ' Do Nothing
End If

To:


blRet = ShowMonthCalendar(mc, dtStart, dtEnd)
If blRet = True Then
    Me.txtDueDate.Text = dtStart
Else
    ' Do Nothing
End If

and the On Change event will trigger ...
you don't have any codes in the AfterUpdate event of the textbox  " txtDueDate"

place something in the afterUpdate event like

Private Sub txtDueDate_AfterUpdate()
MsgBox "Here is  the Afteupdate Event"
End Sub

Open in new window


then
try this change


Private Sub txtDueDate_Click()
On Error GoTo ErrorHandler
'Used for the MonthCalendar control
Dim blRet As Boolean
Dim dtStart As Date, dtEnd As Date

dtStart = Nz(Me.txtDueDate.Value, 0)
dtEnd = 0

blRet = ShowMonthCalendar(mc, dtStart, dtEnd)
If blRet = True Then
    Me.txtDueDate = dtStart
    txtDueDate_AfterUpdate    'Add this line
Else
    ' Do Nothing
End If

Exit_ErrorHandler:
    Exit Sub
ErrorHandler:
    MsgBox "Err Number: " & Err.Number & vbCrLf & _
           "Description: " & Err.Description & vbCrLf & _
           "Procedure:  txtDueDate_Click ", vbOKOnly
    Resume Exit_ErrorHandler

End Sub

Open in new window

ssmith94015:
The After Update event is literally 'after the fact'.  The On Change event will trigger *as soon as the calendar date is entered* ... allowing you to do immediate validation.

It only requires *one simple change":

This:

Me.txtDueDate= dtStart

To this:

Me.txtDueDate.TEXT= dtStart

No other code is needed.

mx


i would  not use the Change event for this purpose.
Ok, I did have code in the after update event, it did not work so I took it out.  Same for the on change event, I donot nkow if it is my set-up or what, but I tried both these events and neither would fire unless I actually typed something in the field rather than simply select a date from the calendar.  I will go back and test again.
ASKER CERTIFIED SOLUTION
Avatar of DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial

Private Sub txtDueDate_BeforeUpdate (Cancel as Integer)

 IF <Validations> Fail Then
    Cancel = True
    Exit Sub
End If

End Sub

mx
ssmith94015: see my  last two posts ...

mx
DatabaseMX, I did compact and repair, but will try to remember to zip it as well next time.
no problem.  ZIP shrank it from 21 MB to 1.4 MB ... amazing.

mx
Both were good suggestions, but this worked with just the change adding the TEXT to the code and the Before seems to satisfy both needs, the user can either type or select from the calendar.

Sandra
ssmith94015,

can you post the codes that solved your problem..

your problem was already given a solution from the post at http:#a37025698 
by calling the event after assigning a value to the textbox.
There is no need for an AfterUpdate event/code at all ...

mx
Attached is the code requested.  The Two procedures solved the problem.
Private Sub txtDueDate_BeforeUpdate(Cancel As Integer)
'Make sure task due date is not past project's due date
Dim dteDueDate  As Date
dteDueDate = Me.txtProjectDueDate
If Me.txtDueDate < Me.txtAssignDate Then
        MsgBox "Sorry, your Task Due date is before the Assign Date." & vbCrLf & _
               "Please correct as this is illogical.", vbOKOnly, "WARNING: INCORRECT TASK DATE!"
        Call CreateCalclass
        Exit Sub
End If

'Make sure task due date is not past project's due date
If Me.txtDueDate > dteDueDate Then
        MsgBox "WARNING FYI:  Task Due date is later that the Project Due Date" & vbCrLf & _
               "of " & Me.txtProjectDueDate & " for this project!  If this is correct, " & vbCrLf & _
               "simply leave the date as it will be saved, if not go back and change.", vbInformation + vbOKOnly, "WARNING: TASK DATE LATER THAN PROJECT DUE DATE!"
End If

End Sub

Private Sub txtDueDate_Click()
On Error GoTo ErrorHandler
'Used for the MonthCalendar control
Dim blRet As Boolean
Dim dtStart As Date, dtEnd As Date

dtStart = Nz(Me.txtDueDate.Value, 0)
dtEnd = 0

blRet = ShowMonthCalendar(mc, dtStart, dtEnd)
If blRet = True Then
    Me.txtDueDate.Text = dtStart
Else
    ' Do Nothing
End If

Exit_ErrorHandler:
    Exit Sub
ErrorHandler:
    MsgBox "Err Number: " & Err.Number & vbCrLf & _
           "Description: " & Err.Description & vbCrLf & _
           "Procedure:  txtDueDate_Click ", vbOKOnly
    Resume Exit_ErrorHandler

End Sub

Open in new window

Only one change, the first comment should be:'Make sure task due date is not prior to assignment date