Link to home
Start Free TrialLog in
Avatar of Fordraiders
FordraidersFlag for United States of America

asked on

format date field on certain entries

access 2010 text box   date picker field  with Short date as format

I sometimes have folks entering or copying and pasting
03312017  with no dashes.
or
332017
or
0312017

Access will not format automatically the short date:  03/31/2017

is there a way to capture this ?

Thanks
fordraiders
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

try using the afterupdate event of the textbox

private sub text0_afterupdate()
if instr(me.text0,"/")=0 then
   me.text0=format(me.text0, "00/00/0000")
end if

end sub
Avatar of Fordraiders

ASKER

Thanks rey,
for 222017
gave me
00/22/2017
fordraiders
There is really no safe way around this, as five digits can be read in so many ways that you can only guess the intention and probably make the wrong guess.

So set the Format property of the textbox to a date format, and an error will pop up if in invalid string is entered. And do educate the users to not use sloppy entry methods for entering important data.

/gustav
One cannot force access to think on his behalf.
To satisfy your specific example assuming:
t=ddmmyyyy 22032017
t=ddmyyyy  2232017
t=dmyyyy  232017
d=format (iif(len(t)=8,format(t,"00/00/0000"),iif(len(t)=7,format(t,"00/0/0000"),format(t,"0/0/0000"))),"dd/mm/yyyy")

Open in new window

You can also train your people to take advantage of Access (and Excel's) ability to expand on what you type.  For example, typing 3/31 will expand to 3/31/2017

typing 2/1 will expand to 2/1/17 which is either February 1st or January 2nd depending on what side of the pond you are on.
ASKER CERTIFIED SOLUTION
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thnx to all