Fixed Length String

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How can I force table entries, through a forms text box, to be a certain
length, and to ignore strings that are not long enough?
 
I don't quite understand what you mean by "ingnore strings that are not long
enough". Also, do you mean that even though the field size of the field in
the table is 30 and the length of the string in the text box is only 5, you
want to add 25 spaces to it to store it as 30 characters?

The basic concept to make a string a specific length is

x = x & space(30-len(x))

You can also control it in the text box by specifying an inputmask that
requires a specific number of characters.

Out of curiousity, though, I wonder why you want to do that. Access stores
only the actual length of the string in the table, so if the string started
out as 5 long, only 5 characters are stored in the table. Doing what you are
asking increases the size of the database by carrying around a bunch of
meaningless data. This also means that much extra data traveling on the
network.
 
Shawn said:
How can I force table entries, through a forms text box, to be a certain
length, and to ignore strings that are not long enough?


Is this what you want?

(in the form's BeforeUpdate event)
If Len(Me.thetextbox) <> certainlength Then
MsgBox "Wrong Length"
Me.thetextbox = Null
End If
 
Thanks Klatuu. What I am trying to do is control the data I have coming into
the text box from a scanner. In one instance, the text box has to be able to
accept a 16 digit, and only 16 digit, package ID (all numeric). If the
barcodes I'm scanning are mis-scanned, which happens, it only picks up half
the digits. I want to eliminate having the erroneous, shorter scans post to
my table, hence the 16 digit requirement.
 
oh, that is quite different, but also easy:

In the After Update event:

If Len(Me.txtPkgID) <> 16 Then
'Do what ever you need to do for a wrong length
End If
 
Beautiful...Thanks!!!

Klatuu said:
oh, that is quite different, but also easy:

In the After Update event:

If Len(Me.txtPkgID) <> 16 Then
'Do what ever you need to do for a wrong length
End If
 
Back
Top