Retstricting Characters During Data Entry

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

Guest

Current version is Access 97. I have a field "Probill Number". This field
is used on several different forms and queries to update information as loads
are scheduled, received, and closed. It is also linked to another database
that tracks productivity using the Probill field. The problem I am having is
that when the Probill is first entered (scheduled) in the system, if the
clerk accidently hits the spacebar before typing, it becomes next to
impossible for others to access that record as needed. The last thing I want
is for people to start accessing the tables to try to find records.

I thought of using an input mask, but unfortunately the Probill number can
be anywhere from 6 to 12 characters long.

Any help in solving this problem would be greatly appreciated.
 
Use the Control_BeforeUpdate Event to check whether the value / data entry
starts with a blank space and if so, post a MsgBox and cancel the update by
setting Cancel = True.

Check Access VB Help on the BeforeUpdate Event of a Control / TextBox.
 
Van T. Dinh said:
Use the Control_BeforeUpdate Event to check whether the value / data
entry starts with a blank space and if so, post a MsgBox and cancel
the update by setting Cancel = True.

Check Access VB Help on the BeforeUpdate Event of a Control / TextBox.

Or just use the AfterUpdate event of the text box to trim leading spaces
from the value. For example,

Private Sub Probill_Number_AfterUpdate()

Me![Probill Number] = Trim(Me![Probill Number])

End Sub
 
Boz said:
. . . The problem I am having is that when
the Probill is first entered (scheduled) in the system,
if the clerk accidently hits the spacebar before typing,
it becomes next to impossible for others to access
that record as needed. The last thing I want is for
people to start accessing the tables to try to find records.

I thought of using an input mask, but unfortunately
the Probill number can be anywhere from 6 to 12
characters long.

If you simply want to disallow spaces in the "Probill Number", in the
KeyPress Event for the TextBox into which the data is being entered, put:

If KeyAscii = 32 Then
KeyAscii = 0
End If

If you only want to disallow spaces at the beginning, then use this code but
substitute the name of your TextBox for <textbox>

If Len(Me.<textbox>.Text) = 0 Then
If KeyAscii = 32 Then
KeyAscii = 0
End If
End If

But, if you have others entering the whole Probill Number, I'd suggest, for
those Forms other than the one where it is initially entered, instead of
just giving them a Text Box to type it in, give them a ComboBox that has its
LimitToList property set to yes, with a RowSource of the valid Probill
Numbers in the system. It will scroll as they type (unless you have set the
AutoExpand property to No, which you don't want to do in this case) each
character, and at some point they may see the whole number and be able to
click to choose it.

(Never make the user do extra work, especially if you can help them avoid
making errors while you are, potentially, saving them some keystrokes.)

Larry Linson
Microsoft Access MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top