The original issue was how to enter and store a date with no year.  Full description of the issue is at the end of this email.
A couple of notes:
1. If the text field is nulled out due to error trapping, i.e. a month is > 12, then the null symbol is not autoselected when Skipping to the field or using Set Focus to the componentID.  I tried AUTOSELECT and SELECTALL properties, but no luck. So I figured, ok, leave the old value in the field so user can see what was typed in error.
2. I do locate the [DateColumn] that's being updated on the form after the three variables.  It shows what is really in the database - sort of a digital security blanket.
3. The Variable Edits all have Autoselect checked.
4.  I used Text data type for the variables (vs. integer) for better error trapping and consistent error messages.
5. Thanks to everybody for their suggestions.  I hope this is helpfull to somebody.
6.  There's understandable odd behavior if user tries to [shift-tab] backwards from month to day but I can't trap [shift-tab] with (Lastkey(0 or 1)), it shows as [Tab].  Anybody have ideas?

Thanks again to all.  
Doug

Here's what I did:

1) Define 4 variables, either in a command file or On Before Start EEP:
SET V vDateDD TEXT = NULL, +
  vDateMM TEXT = NULL, +
  vDateYYYY TEXT = NULL, +
  vNewDate DATE = NULL
RETURN


2) Locate vDateMM, vDateDD and vDateYYYY in that order as separate variable edits on the form.

3) Each variable has it's own On Exit From EEP for preliminary error check:
vDateMM:
IF vDateMM IS NULL OR vDateMM = ' '  THEN
    --If no month entered, assume date will not be entered.
    --Skip out of date entry to next field.
    PROPERTY [SomeOtherCompID] SET_FOCUS 'true'
    GOTO Done
ENDIF

IF (NINT(vDateMM)) > 12 OR +
      vDateMM NOT BETWEEN '0' AND '9' THEN

    PAUSE 2 USING 'Invalid Month' +
      CAPTION 'caption' Button 'OK' +
      OPTION ICON_FILE icons\information.bmp
    --Re-enter month if > 12 or not numeric
    SKIP TO vDateMM
    GOTO Done
ENDIF

--If month is OK, go to enter the day
SKIP TO vDateDD

LABEL Done

RETURN

vDateDD:
IF vDateDD IS NULL OR vDateDD = ' ' THEN
    --SKIP MM & YYY fields, go to
[SomeOtherCompID]
    SET V vDateMM = NULL
    PROPERTY 
[SomeOtherCompID] SET_FOCUS 'true'
    -- or you could: SKIP TO vDateDD to re-enter DD
    GOTO Done
ENDIF

IF (NINT(vDateDD)) > 31 OR +
      vDateDD NOT BETWEEN '0' AND '9' THEN
    PAUSE 2 USING 'Invalid Day' +
      CAPTION 'caption' Button 'OK' +
      OPTION ICON_FILE icons\information.bmp
    --Re-enter date
    SKIP TO vDateDD
    GOTO Done
ENDIF

--Go to enter year
SKIP TO vDateYYYY

LABEL Done

RETURN


vDateYYYY:
IF vDateMM IS NOT NULL AND vDateDD IS NOT NULL THEN
    IF vDateYYYY = ' ' THEN
        SET V vDateYYYY = NULL
    ENDIF
    --Create a date; if no year entered, default year is 1004
    --1004 allows for Feb 29 (thank you Larry)
    SET V vNewDate = +
      (IFNULL(vDateYYYY, +
      (RDATE((NINT(vDateMM)),(NINT(vDateDD)),1004)), +
      (RDATE((NINT(vDateMM)),(NINT(vDateDD)), (NINT(vDateYYYY)) ))))

    --if valid date is not created or YYYY is less than four digits
    --  it's an error.
    IF vNewDate IS NULL OR +
          ((SLEN(vDateYYYY)) < 4 AND vDateYYYY IS NOT NULL) OR +
          vNewDate > .#DATE THEN
        SET V vMsg = +
          (.vDateMM + '/' + .vDateDD + '/' + .vDateYYYY)
        SET V vMsg = (.vMsg & 'is not a valid date.')
        PAUSE 2 USING .vMsg +
          CAPTION 'caption' Button 'OK' +
          OPTION ICON_FILE icons\information.bmp
        SKIP TO vDateDD
        GOTO Done
    ENDIF

    -- If the date is valid, go ahead and update the table.
    UPDATE [TableName] SET [DateColumn] = .vNewDate +
      WHERE [clause]
    PROPERTY TABLE [TableName] 'REFRESH'

ENDIF

LABEL Done

RETURN


Orginal Issue:
My question was on storing a birthdate without the year.  Some adults don't care to give their birthyear, so all we have is MM/DD in DateOfBirthColumn.  For the kids (who aren't so particular), we want to store MM/DD/YYYY in DateOfBirthColumn so we can determine their age for placement in classes as well as printing the birthday list.  So, for the adults who don't give us a birth year, I'm thinking the best thing is to store something like MM/DD/1000 or MM/DD/0001 or some obviously bogus year.

Reply via email to