INPUT MASK OF FEBRUARY I GUESS IS BROKEN "29"/\2/0000;0; Date-Time (1 Viewer)

MicroAbdel

New member
Local time
Today, 08:15
Joined
Aug 9, 2020
Messages
26
Remove the input mask entirely and use a button to store the date. In the click event, take the current year concatenated to march 1 and then subtract one day. That will give you the last day of February which will be the 28th or 29th depending on whether year is a leap year or not. OR since the actual month and day seem to be irrelevant, just store the year.
Anyway ty for ur time i just want to tell u I'm not a VB user at all ;( , sadly i just go to give the client to type only Days and Years, but pls if u have any link to understand ur method its rly appreciate it <3
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 11:15
Joined
Feb 19, 2002
Messages
43,264
input masks for dates cause more problems than they solve. I never use them. One thing is that they prevent the pop up calendar from working. That is not an issue for you, just info to tuck away. If the user just enters the year, you can add code to the control's BeforeUpdate event to calculate a date. I would use an unbound control for the year entry and put the actual date in a bound field. You should set the locked property of the bound date control to Yes so that the user cannot change the date. Now for the code. You can handle the code. It is one line and it uses two functions you will find useful.
Code:
Me.txtMyDate = DateAdd("d",-1, cdate(Me.txtYear & "/03/01"))
Me.txtMyDate needs to be the name of the control you want the date to end up in. "Me." is the way you reference a control within the code module of a form or report. As you'll notice, after the . you'll see intellisense which will help you complete the name of the control by picking from a list. It is always best to give controls meaningful names or use the name of the ControlSource they are bound to.
Me.txtYear is the name of the unbound (no ControlSource and this will not be saved to the table) control where the user enters the year.
DateAdd() is a function that adds a numeric value to a date. The first argument = "d" and that means day. The second argument = -1 and that is the interval you want to add (or in this case subtract). The third argument is an embedded function cDate(). cDate() converts the embedded string to a date data type. The string is built by concatenating the year with /03/01 which will create a date = someyear/03/01 or March 1st.

Lots of stuff in only a few characters.

Here's an example printed in the immediate window that uses a hard-coded year.
print dateadd("d",-1, cdate(2020 & "/03/01"))
2/29/2020
 

Users who are viewing this thread

Top Bottom