Format Date/Time Probem

MarkL

Registered User.
Local time
Today, 09:52
Joined
Dec 16, 2009
Messages
12
Hi, hope someone can help me.

I have a table where a Field Name has Data Type of Date/Time with Format "mm"/"dd" and Input Mask of Short Date 99/99/0000;0;_

In the form the Text Field with source from that Field Name has Input Mask as 99/99;_

The text field in the form shows __/__ in the form when clicked into and when type e.g. 12/01 then click off field, it shows 12/31/2009 in the text field, but I want it to only show 12/01. I want to use Date/Time so if incorrect date is inserted, the error message box comes up. I can force it with using Date Type of Text to only permit 12/01, but then it does not prevent putting in an incorrect date (e.g. 18/99).

What am I doing wrong? Help. Thanks.
 
Hi, hope someone can help me.

I have a table where a Field Name has Data Type of Date/Time with Format "mm"/"dd" and Input Mask of Short Date 99/99/0000;0;_

In the form the Text Field with source from that Field Name has Input Mask as 99/99;_

CHECK out the help menu for INPUT MASKS. try changing it in the table maybe? Check out the characters you use for the manual masks
 
Personally, if you only want the month and the day, I would

1. Not store it as a date field (make it a text field)

2. Use TWO text boxes, one for month and one for day(or even better, two combo boxes so you can more easily limit the available values) and store each in its own field.

Since a date field really needs the whole date (month, day, and year) to be stored, it will store the current year as default if you choose only the month and day. However, if you are going to use it later as ONLY Month and Day, it really makes no sense to store a year which has no meaning in that context.
 
Personally, if you only want the month and the day, I would

1. Not store it as a date field (make it a text field)

2. Use TWO text boxes, one for month and one for day(or even better, two combo boxes so you can more easily limit the available values) and store each in its own field.

Since a date field really needs the whole date (month, day, and year) to be stored, it will store the current year as default if you choose only the month and day. However, if you are going to use it later as ONLY Month and Day, it really makes no sense to store a year which has no meaning in that context.

Thanks, looks like that is the way to go. I did try things with the Input Mask and Format in the Table, but it seems it will not work, so going with combo boxes solves the problem.
 
Here's one way for using two comboboxes:
Code:
Private Sub Form_Load()

'Load Months Combobox
 Me.cboMonths.RowSourceType = "Value List"
 For intMonth = 1 To 12
  Me.cboMonths.AddItem Format(DateSerial(Year(Date), intMonth, 1), "mmmm")
 Next intMonth

End Sub

Private Sub cboMonths_AfterUpdate()

i = Day(DateSerial(Year(Me.cboMonths & "-" & "1-" & "2008"), Month(Me.cboMonths & "-" & "1-" & "2008") + 1, 0))

'Set up Days Combobox
Me.cboDays.RowSourceType = "Value List"
Me.cboDays.RowSource = "" 'Erase previously days from cbo
For intDay = 1 To i
 Me.cboDays.AddItem intDay
Next intDay

End Sub
This code uses the year 2008, which was a Leap Year. This ensures that when the month of February is selected, the days available will be 29.

Since you don't differentiate between years, this is best you can do. If a year were available or if it was always the current year, this could be modified so that the days available for February were year specific.
 
Hi missinglinq,

I inserted the above code as stated (substituting the names I use for the combo boxes) to try it, but on Compile got Compile Error that state for intMonth and intDay "Variable not defined." Help. Thanks.
 
Last edited:

Users who are viewing this thread

Back
Top Bottom