View Full Version : Size of a text field - how to block it?


Leen
05-11-2007, 05:16 AM
Hi,

I have created a table using vba. To create the fields I used the folowing statement:
.Fields.Append .CreateField("SNAM1LC", dbText, 3)

In this case the fieldlength is maximum 3. However, I'd like to force in some way that that field can only have inputs of exactly 3 characters. So that during input no mistakes can be typed by typing for example only 2 characters.

Is there a way to integrate this into the table-definition? To "block" the length of a text field?

Thanks a lot on forehand!
Leen

Dennisk
05-11-2007, 05:29 AM
if the max length is 3 characters then thats all you can enter. look up input mask in help.

Leen
05-16-2007, 03:03 AM
HI,

When I look to the help about InputMask, this property applies only on combobox and textbox.
However, I want the restriction that when entering data in a TABLE, the fieldlenght entered should be EXACTLY 3 (Not maximum 3). So I think it should be one of the properties of a field, but I don't know how to apply this.

It tried via:
tbl.Fields!SNAM1LC.ValidationRule = "LEN(SNAM1LC) = 3"
tbl.Fields!SNAM1LC.ValidationText = "Length of the languagecode must be equal to 3"
tbl.Fields!SNAM1LC.ValidateOnSet = True

But this doesn't work. My goal is that, in the model of the table, in the field SNAM1LC only data can be entered having 3 characters.

Some idea how to achieve this?
Thanks a lot on forehand,
Leen

Dennisk
05-16-2007, 03:38 AM
Data should only be entered via a form. However you can use an input mask to ensure that 3 characters are always entered. open your table in table design mode, position your cursor in the input mask field and press f1 to look up the examples for text.

RoyVidar
05-16-2007, 04:09 AM
Try with brackets

"LEN([SNAM1LC]) = 3"

Alternatively, if it doesn't work, add it to the tabledef validation rule property.

> Data should only be entered via a form.

Sometimes it might come from an import file, from Excel, Word, VB, VBScript or other sources that are not Access forms, in which case engine level validation might be necessary to ensure data integrity.

Leen
05-16-2007, 04:45 AM
Thanks!!

With the brackets it works!

Leen