View Full Version : Problem With Input Mask On Form


crhodus
01-02-2002, 06:17 AM
I've got an imput mask on one of my forms that is having problems. Since the first of 2002, one of my fields will not record the year 2001 correctly.

This field on the form (named STDate) has 99/00;;_ for the imput mask. Also, the table that houses this data has an imput maks of 99/00;;_

This field is set up so that only the month and year are displayed. The user only has to enter in 11/01 for the month and date November 2001. After the user types in the date, 11/2001 is displayed in the field.

The problem that is happening now is that when the user enters in 11/01, Access is changing the year to 2002, so that 11/2002 is displayed.

Can anyone help me?

Thanks!


[This message has been edited by crhodus (edited 01-02-2002).]

David R
01-02-2002, 01:50 PM
Can you post the code that allows you to only enter the month and year? Whenever I enter xx/xx, it defaults to the current year, and I'd be curious to see how you got around that (it's probably possible, I've just never put the brainpower into it).

You might be able to make a workaround that checks if the date entered is later than today, and takes a year off of the data with DateAdd().

HTH,
David R

Pat Hartman
01-02-2002, 05:33 PM
There is nothing in the mask that can tell Access which of the three parts of date (m,d,y) that you are omitting. It therefore analyzes the parts that are entered and makes its own determination. The normal assumption is that the year part is what has been omitted, therefore Access defaults to the current year. Last year the default would have been '01 for 2001 and this year it is '02 for 2002.

To get around this problem, make the form field unbound and place some VBA code in the field's AfterUpdate event to populate the "real" field in the table.

1. Make sure that the control name (find it on the other tab of the properties dialog) is not the same as the name of any of the fields in the form's control source. If you built this form with the wizard the wizard would have used the name of the bound field as the control name so you'll have to change it. I usually just add "txt" as a prefix for easy remembering. So MyField (field name) becomes txtMyField (control name).
2. Remove the field name from the controlsource to make the control "unbound".
3. In the AfteUpdate event of the field put code to populate the table/query field -
Me.MyField = Left(Me.txtMyField,2) & "/01/" & Right(Me.txtMyField,2)
This code takes the first 2 characters of user entered data and places it in the "month" position, uses literal /'s and an 01 for the "day" position, and then takes the last 2 characters of user entered data and places it in the "year" position.