Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Using Calendar not firing After Update event

Posted on 2011-10-25
40
Medium Priority
?
315 Views
Last Modified: 2012-05-12
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?
0
Comment
Question by:ssmith94015
  • 20
  • 14
  • 6
40 Comments
 
LVL 75
ID: 37025464
Normally, you do validation in a Before Update event ... does the calendar have that?
What calendar are you using ?

mx
0
 

Author Comment

by:ssmith94015
ID: 37025538
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.
0
 

Author Comment

by:ssmith94015
ID: 37025554
Nope, did not get fired apparently even in the Before update event.
0
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 
LVL 75
ID: 37025559
Which Leban's calendar ?

mx
0
 

Author Comment

by:ssmith94015
ID: 37025574
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
0
 
LVL 75
ID: 37025610
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
0
 

Author Comment

by:ssmith94015
ID: 37025630
Actually, the first link you have is the one I used (i have it bookmarked already).  
0
 
LVL 75
ID: 37025644
ok .... yes I see ... it's the same.
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 37025698

<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

0
 
LVL 75
ID: 37025765
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
0
 
LVL 75
ID: 37026017
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
0
 

Author Comment

by:ssmith94015
ID: 37026155
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.
0
 

Author Comment

by:ssmith94015
ID: 37026167
Ok, I got it to work using the Lost Focus even.  Dang, that was like pulling teeth!
0
 

Author Comment

by:ssmith94015
ID: 37026203
Cap, there is no Calendar click event as the calendar is virtual, created in code, not being resident on a form.
0
 
LVL 75
ID: 37026205
Well ... it definitely worked for me ...

mx
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 37026262
<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.
0
 

Author Comment

by:ssmith94015
ID: 37026266
Let me clean out the database of proprietary information and post.
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 37026291
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
0
 
LVL 75
ID: 37026297
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
0
 
LVL 75
ID: 37026313
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
0
 

Author Comment

by:ssmith94015
ID: 37026423
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
0
 
LVL 75
ID: 37026460
Just an fyi ... in the future
1 Compact & Repair the db
2 Zip it up before upload.  This db is 21 Mega Bytes.

mx
0
 
LVL 75
ID: 37026559
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
0
 
LVL 75
ID: 37026590
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 ...
0
 
LVL 75
ID: 37026623
see attached db (1.4 MB)


TrackingShell-MX01.zip
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 37026685
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

0
 
LVL 75
ID: 37026723
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
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 37026773


i would  not use the Change event for this purpose.
0
 
LVL 75
ID: 37026803
I would.

mx
0
 

Author Comment

by:ssmith94015
ID: 37026820
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.
0
 
LVL 75

Accepted Solution

by:
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform) earned 2000 total points
ID: 37026829
However, if you are typing in a date ... there would be an issue ... So ... overall, the Validation code should be in the Before Update event ... as is the usual case ... which will trigger when you attempt to leave the text box.  After Update event is too late.
0
 
LVL 75
ID: 37026847

Private Sub txtDueDate_BeforeUpdate (Cancel as Integer)

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

End Sub

mx
0
 
LVL 75
ID: 37026854
ssmith94015: see my  last two posts ...

mx
0
 

Author Comment

by:ssmith94015
ID: 37026855
DatabaseMX, I did compact and repair, but will try to remember to zip it as well next time.
0
 
LVL 75
ID: 37026873
no problem.  ZIP shrank it from 21 MB to 1.4 MB ... amazing.

mx
0
 

Author Closing Comment

by:ssmith94015
ID: 37026894
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
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 37026989
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.
0
 
LVL 75
ID: 37027007
There is no need for an AfterUpdate event/code at all ...

mx
0
 

Author Comment

by:ssmith94015
ID: 37027379
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

0
 

Author Comment

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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Implementing simple internal controls in the Microsoft Access application.
Beware when using the ListIndex and the Column() properties of a listbox in Access 2007.  A bug has been identified in the Access 2007 listbox code which can cause the .ListIndex property to return a -1, and the .Columns(#) property to return a NULL…
The Relationships Diagram is a good way to get an overall view of what a database is keeping track of. It is also where relationships are defined. A relationship specifies how two tables connect to each other. As you build tables in Microsoft Ac…
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…

577 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question