Results 1 to 6 of 6
  1. #1
    WickidWe is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2013
    Posts
    123

    VBA Form Validation

    Hi,

    The code below is to check on a form whether the From Date is Less than the To Date.
    For some Reason it is not coming up with the error
    Code:
    If Format(Me.txtFromDate, "dd/mm/YYYY") < Format(Me.txtToDate, "dd/mm/YYYY") Then
     MsgBox "'Between Dated' must be more than Start Date!", vbExclamation
        Exit Sub
        Else
    Im sure it has something to do with the fomatting of the date but I cant figure it out.

    I tried the same code with a ">" instead and it worked although it shouldnt. but only if the dates where in the same year.
    Strange......



    Any Ideas?

  2. #2
    WickidWe is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2013
    Posts
    123
    No Matter....
    I Had the < around the wrong way

  3. #3
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,917
    The Format function always turns the results into a string. Try just comparing the controls by themselves.

  4. #4
    WickidWe is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2013
    Posts
    123
    thats the ticket....Thanks

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Format results in a text string and alpha sort rules. This means "23/12/2012" is not less than "21/12/2013".

    Either don't use Format and compare true date values or use "YYYYMMDD"
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,917
    Glad we could help.

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

Similar Threads

  1. Form Validation Rule
    By galkej in forum Forms
    Replies: 4
    Last Post: 07-01-2012, 06:38 PM
  2. Access form and validation
    By Hello World in forum Forms
    Replies: 3
    Last Post: 09-18-2011, 05:32 AM
  3. Validation at form level
    By Kris in forum Forms
    Replies: 1
    Last Post: 06-28-2011, 06:48 AM
  4. Validation Lookup on form
    By alperale in forum Forms
    Replies: 17
    Last Post: 01-28-2011, 10:48 AM
  5. validation with a datasheet form
    By Grooz13 in forum Forms
    Replies: 1
    Last Post: 01-12-2011, 10:42 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