Input masks - 1 or many?

Rothron

Registered User.
Local time
Today, 21:54
Joined
Jul 19, 2000
Messages
17
Can you have more than one input mask for a field? I have a field which either requires a number in the format ####-##-###-#### or a date in the form (##/##/##) (including the brackets. Is there any way this can be done?

Any suggestions gratefully received.
 
You cannot realy have more than one format associated with a field. You could assign a format in code but you would somehow have to trap the type of input the user was going to use befor they entered it. One way of doing this this would be:
Remove any formating from the table field formating
Add a Yes/No field to your table. This will flag whether it is a date format or not.
Decide which default format you want and apply this to the text box on a form and also set the yes/no box to the default.

e.g if the default is 'not a date' and the user wants to enter a date then the user explicitly select date format.

Once you have got this info you then assign a format to the text box in your code.

Whilst the above may solve your immediate problem Personnaly I would not do it. I would alter the table so that it has both a text field for the first format and a date field for the second format. With your method I believe you a storing up problems for the future e.g You may have problems manipulating annd querying data due to the fact that you are using one data type to hold two different data types. Whilst Access is very good at doing automatic type conversions and in recognising date formats in a string it is not perfect. You may also experience problems if you want to use date part or agrregate functions on your dates simply because you have a mix of formats. For example how would you extract a month from the field? how would you perform date maths e.g take one date from another?
You may also have future problems because an access date is realy just a formated number (This is a very simplistic definition) as your other format is also a number you may perform some date maths and think the results are o.k when in fact they are not.
Overall I do not think it is a good idea to mix data types in a single field

Hope this helps
Regards
Trevor from www.accesswatch.co.uk
 

Users who are viewing this thread

Back
Top Bottom