+ Reply to Thread
Results 1 to 4 of 4

Comparing one date to another

  1. #1
    Registered User
    Join Date
    12-09-2007
    Posts
    10

    Comparing one date to another

    I swear this worked when I tried it a couple of days ago... now suddenly it doesn't

    It's not doing the bit in bold, checking the date entered is greater than the date in txtDateReg.

    Please Login or Register  to view this content.

  2. #2
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229
    An InputBox returns a string, so the comparisons are evaluating things alphabeticaly rather than numericaly. This routine uses CDate to convert those strings to dates. It also uses a more compact structure.
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    12-09-2007
    Posts
    10
    Thanks that worked

    Could you explain this line in a little more detail please?

    Thanks

    Please Login or Register  to view this content.

  4. #4
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229
    Running the following code, the user can either press Cancel, press OK before entering a value or enter something. In the first two cases, userInput will equal vbNullString.
    To distinguish between those:
    StrPtr(userInput) returns the memory location where the value of the variable is stored.
    If OK is pressed, the value vbNullString is assigned to the variable userInput, which involves putting that value in a memory location.
    If Cancel is pressed, no value is assigned to userInput and its pointer remains 0, i.e."unassigned".
    StrPtr(UserInput)=0 will test if the Cancel Button was pressed.

    Please Login or Register  to view this content.
    Note also that if "123" is entered, it is read as a string not a number. These are two of the reasons that I prefer to use the
    Application.InputBox method rather than InputBox function used in the posted code.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1