Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2012
    Location
    India
    Posts
    42

    Exclamation Unanswered: Validation through calender control

    Hi,

    I've a little concern about Validation rule on date/time field on form:

    I'm using Validation rule " Between #01-Apr-12# And #31-Mar-13# " on Challan_date field and it's working fine while entering manual entry but when someone uses calender control, it doesn't work at all. It accepts any date set through Calender control.

    My concern is to restrict user to enter date between the criteria set.

    Calender Control code:
    ---------------
    Private Sub cmdCalendar_Click()
    Set ctlIn = Me.Controls("Challan_date")
    DoCmd.OpenForm "frmCalendar"
    Me.Cln_Mode.SetFocus
    End Sub

    ---------------

    Please guide me to do so.
    Thanks in advance.

  2. #2
    Join Date
    Oct 2003
    Location
    London
    Posts
    341
    I've never used the calendar controls so I don't even know if this would be a solution that would work but if there is an event handler for after_update, get the after update routine to

    1. check that the date selected meets your validation rule.

    2. If it meets the rule then do nothing

    3. If it doesn't meet the validation rule, display error message and return focus to the calendar.

  3. #3
    Join Date
    Jan 2012
    Location
    India
    Posts
    42
    Thanks for your guidannce, but the following code is not working. Can you help me?

    If Me.Challan_date < #1/4/2012# > #3/31/2013# Then
    MsgBox ("Invoice date is greater or less than your Financial year."), vbCritical, "Error"
    Me.Challan_date = ""
    Me.Challan_date.SetFocus
    End If

    Thanks
    Anuj

  4. #4
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    1. The AfterUpdate event will only be triggered when the user change the value of a control. It won't be if the value is changed through some VBA code.

    2. For testing whether a given value (here a date) is between two other values, you should use (.Value is not mandatory):
    Code:
    If (Me.Challan_date.Value < #1/4/2012#) Or  (Me.Challan_date.Value > #3/31/2013#) Then
    or:
    Code:
    If Eval(Me.Challan_date.Value & " NOT BETWEEN #1/4/2012# AND #3/31/2013#") Then
    3. If "frmCalendar" is open Modal, then you can test the value on the line following the one where it's open:
    Code:
    DoCmd.OpenForm "frmCalendar", , , , , acDialog
    
    ' The next line will not be executed before frmCalendar is closed.
    '
    If (Me.Challan_date.Value < #...
    Have a nice day!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •