Making mask in a table

U

Una Tutta

I want to make a mask in a table. It should be min 4 numbers in txt format
Eks. 1 should be 0001 not 1, 123 shoul be 0123.
 
J

Jerry Whittle

Let's say that the field size is 10. The input mask would be:

0000######

That makes the first four digits mandatory and the last 6 digits optional.
If any of the last 6 aren't entered, they are NOT stored as spaces.
 
W

Wayne-I-M

Hi Una

I would not bother with a mask. - Up to you though.

If you are using a form to update the record I would use the AfterUpdate
event of the control to alter the data. Something like this


Private Sub FieldName_AfterUpdate()
If Len(Me.FieldName) < 5 Then
Me!FieldName = Right("0000" & Me!FieldName, 4)
End If
End Sub

Change "FieldName" to what it is on the form and it should be OK.

If the data is "always" 4 digits you could set this as a variable and use
something like this

Private Sub FieldName_AfterUpdate()
Dim SomeName As Long
If SomeName = Len("FieldName") < 4 Then
Me!FieldName = Right("0000" & Me!FieldName, 4)
End If
End Sub

Change FieldName again and I wouldn't use "SomeName" so change this as well.
Note this will of course trim the data to 4 so don't use if this is not
what you want (not really sure from your post). Or include an "else" to the
above to show longer strings.




Hope this helps
 
W

Wayne-I-M

ooops

If SomeName = Len("FieldName") < 4 Then

Should be

If SomeName = Len("FieldName") < 5 Then
 
Top