472,988 Members | 2,845 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,988 software developers and data experts.

Converting date in a form

2 2Bits
I have one user who inputs her dates using a period (today would be 4.27) and Access is taking that as 4:27 AM. I don't want to change the input mask and mess up the other 8 people using the same input form. Suggestions are appreciated.
Apr 27 '22 #1
6 12166
isladogs
443 Expert Mod 256MB
Shouldn't your user be entering dates including the year e.g. 4/27/2022?
You could always use the Replace function to replace any periods (.) with /

Replace(Name of your date control here, ".","/")

What is the input mask you are using?
Apr 27 '22 #2
Machi413
2 2Bits
I'm not currently applying an input mask on date fields in my forms since some use 4-27 and others 4/27, both of which are understood in Microsoft as 4/27 of the current year. Even if my [difficult] user put the year with her periods (4.27.22), Access sees that as 4:27:22 AM. I've tried directly replacing the dot with a dash or slash several ways using Replace but cannot get it to work. I'm fairly new to Access, and though I have created 50+ queries and forms, this issue has me stumped.
Apr 27 '22 #3
isladogs
443 Expert Mod 256MB
Just tested this using a field with a date/time datatype.
I'm based in the UK where the date format is dd/mm/yyyy

Entering 27/4 or 27.4 or 27-4 are ALL correctly interpreted as 27/04/2022
Apr 27 '22 #4
zmbd
5,501 Expert Mod 4TB
How about a nag box??
In the KeyPress event of the control
Expand|Select|Wrap|Line Numbers
  1. Private Sub Text0_KeyPress(KeyAscii As Integer)
  2.   If KeyAscii = 46 Then MsgBox "Please do not use periods/dots in dates", vbCritical, "Invalid Key"
  3. End Sub
I like this one as the feedback is immediate.
Or in the BeforeUpdate event you can use
Expand|Select|Wrap|Line Numbers
  1. Private Sub Text0_BeforeUpdate(Cancel As Integer)
  2.   If InStr(Text0.Value, Chr(46)) Then
  3.     Cancel = True
  4.     Text0.Undo
  5.     MsgBox "Invalid Date Format - Please do not use periods/dots in this field", vbCritical
  6.   End If
  7. End Sub
This will wait until the user presses enter/tab/clicks out of the date control - if there's a period then the nag, cancels the update and reselects the control.
Keep in mind that no matter where in the world you are, internally Access will ALWAYS handle dates in #MM/DD/YYYY# format - in tables, code, etc... it's been a source of errors in numerous posts from locations outside of the USA.
Apr 27 '22 #5
NeoPa
32,550 Expert Mod 16PB
I believe this is a situation where the user should bend to the system rather than vice-versa. I see no rational reason why any system should cater for someone failing to use it properly. Unless you have a valid format where dates are entered that way of course, but I know of nowhere that would be the case.

zmbd:
Keep in mind that no matter where in the world you are, internally Access will ALWAYS handle dates in #MM/DD/YYYY# format - in tables, code, etc... it's been a source of errors in numerous posts from locations outside of the USA.
I'm not sure I follow you. Internally dates are stored as floating point numbers. Display formats are not in any way relevant to how data is stored.

Alternatively, #mm/dd/yyyy# formats are also not universally supported. An example is here in the UK. Date entry in a form will recognise dd/mm/yyyy where possible to interpret that way and only use mm/dd/yyyy when it cannot.

EG. 1/8/2022 will be treated here as 1st August 2022 rather than 8th January as it would be across the pond. Where you see the overlap is for something like 1/13/2022 which, even here, is recognised as impossible when interpreted as dd/mm/yyyy, so is automatically translated to mm/dd/yyyy.

More on dates etc can be found at Literal DateTimes and Their Delimiters (#).
Apr 29 '22 #6
zmbd
5,501 Expert Mod 4TB
NeoPa: I'm not sure I follow you. Internally dates are stored as floating point numbers. Display formats are not in any way relevant to how data is stored.
Yes, I over simplified, internally the date is stored as a floating point number.
Apr 29 '22 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: wireless | last post by:
In our database is a decimal field with format YYMMDDhhmmss.9999999999 where the 9s are random digits. I'm trying to strip off just the YYMMDD and put it in date form. So far I came up with:...
3
by: Gary Smith | last post by:
I my SQL Datareader I am loading the date data into text box. Here is my code txtActOpenDate.Text = MyDataReader("ActOpenDt").ToString() txtActOpenDate.Text is displaying the date and...
4
by: Lisa Jones | last post by:
Hi Can someone tell me How do you get selected date form MonthCalendar control Thanks so muc Lisa
3
by: NateM | last post by:
How do I convert any given date into a milliseconds value that represents the number of milliseconds that have passed since January 1, 1970 00:00:00.000 GMT? Is there an easy way to do this like...
9
by: Alok yadav | last post by:
i am using a webservice in which a method is serach. i use this method which accept a argument of date type in dd/MM/yyyy formate. i have a textbox which accept the date from the user, when i...
6
by: marc | last post by:
hi im trying to convert Date() into a unix timestamp so i can stick the result into a mysql db, please help!
3
by: Jef Driesen | last post by:
How can I convert a date string to a number (e.g. a time_t value or a tm struct)? I know about the strptime function, but then I have to know the format string. And that is a problem. I'm trying...
2
by: jacc14 | last post by:
Hi Hope there is someone out there that can help. I am sure this is an easy one although not easy to explain. I have a form which produces a report using a query. On the form I have a start and...
4
by: gubbachchi | last post by:
Hi, I have an issue regarding the php date format. I choose the date from date-picker which is in the format date('Y-m-d') i.e. 2008-09-12, then I will store this date in the variable $date_id and...
1
by: =?Utf-8?B?bGF3ODc4Nw==?= | last post by:
i am looking for some MS Excel formula or MS Visal Basic Marco for converting Date to Lunar Date. tks
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
3
SueHopson
by: SueHopson | last post by:
Hi All, I'm trying to create a single code (run off a button that calls the Private Sub) for our parts list report that will allow the user to filter by either/both PartVendor and PartType. On...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.