Date Format

  • Thread starter Thread starter Todd C
  • Start date Start date
T

Todd C

I set the date format to yymmdd on my forms and tables. however, when i type
the date in that format, it says that it is not a valid format. How do i do
this and allow it to work?
 
Hello Todd.

Can you see a difference in how our two posts begin?
Todd C said:
I set the date format to yymmdd on my forms and tables. however,
when i type the date in that format, it says that it is not a valid
format. How do i do this and allow it to work?

You didn't change the date format but you changed the format property
of a control. That property decides on you the values are "displayed"
and has nothing to do with how text that you enter is interpreted.
You still have to enter a date in a way that the computer understands
like m/d or m/d/y (or m.d.y depending on the regional settings of your
computer).
You can make data entry easier by using an InputMask that already
contains the date separators: 00/00/0000
 
As Wolfgang says if you want a date you need to have something the access
will see as a date. But if you really want to use YYMMDD you would need to
convert this to a date - something like

SELECT YourTable.Datefield, YourTable.InputField,
CDate(Mid([InputField],5,2) & "/" & Mid([InputField],3,2) & "/" &
Mid([InputField],1,2)) AS [Date]
FROM YourTable;

Of course this could be done AfterUpdate on your input control on the form
Private Sub InputField_AfterUpdate

Me.Datefield = CDate(Mid([InputField], 5, 2) & "/" & Mid([InputField], 3, 2)
& "/" & Mid([InputField], 1, 2))
End Sub

You may be better using Left, Mid, Right - I have just used Mid to show you
how it works

But this seems a lot of work for something that access will do anyway (there
are quite a few date formats that access will produce)

Good luck
 
Back
Top