Results 1 to 5 of 5
  1. #1
    aparnawangu is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Jul 2015
    Posts
    40

    Date Validation In calendar

    Hi Team,


    I have a query regarding Date validation in access.
    I have a field called Enquiry date and the criteria is that the user should be able to select dates past 15 days only beyond that the system should not allow dates to be selected.
    Further the user should not be able to select the date later than current date.
    Pls suggest me the solution.


    Thanks Aparna

  2. #2
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Create a query that contains criteria that limits your data values, and then use that query as the Source of your Enquiry date selection field.

  3. #3
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Using the native DatePicker, that's been available since v2007, is no different than physically entering a date via the keyboard, and so you can do data validation using the Control's BeforeUpdate event.

    Replacing DateFieldName with the actual name of your Textbox that holds the date, this will do the job:

    Code:
    Private Sub DateFieldName_BeforeUpdate(Cancel As Integer)
     If Me.DateFieldName > Date Or Me.DateFieldName < DateAdd("d", -15, Date) Then
       MsgBox "Invalid Date! Try Again"
       Cancel = True
     End If
    End Sub

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  4. #4
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Sorry, I was assuming that they were picking the dates from a bunch of records that they had in a field in a table or query. However, it could be an unbound field.
    It isn't entirely clear, so I probably should not have assumed that...

  5. #5
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    You were probably mislead by the OP's statement "I have a query;" saying "I have a question" would probably have been less confusing!

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

Please reply to this thread with any new information or opinions.

Similar Threads

  1. how to get a pop up calendar on a date field
    By accessmatt in forum Forms
    Replies: 3
    Last Post: 11-12-2014, 07:48 PM
  2. Calendar date on a tab page
    By FJM in forum Forms
    Replies: 4
    Last Post: 10-22-2014, 05:18 AM
  3. Date ranges using Calendar control
    By LilMissAttack in forum Forms
    Replies: 8
    Last Post: 08-25-2011, 10:04 AM
  4. Replies: 3
    Last Post: 10-12-2010, 11:15 PM
  5. Set Calendar to default to today's date
    By RickM in forum Access
    Replies: 1
    Last Post: 02-22-2009, 04:51 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums