Full Version: Data Entry Question
UtterAccess Discussion Forums > Microsoft® Access > Access Forms
MikeGSuppe
Greetings

This area is not my strength

I would like to check the contents of what is entered in a field and make sure the there is no "/" in the contents.

ie

I need

PO 123-011512

not

PO 123/011512

to be picked up if enetered;

but the twist is that there cannot be more that 9 numbers in the whole statement

~mike
DanielPineault
You could build a validation code in your form's before update event

CODE
'Untested air code
If Len(Me.YourControlName)>9 Then
   msgbox "your PO exceeds the number of allowable characters.  Please verify your entry and try again.", vbCritical+vbokonly,"Validation Error"
   Me.YourControlName.SetFocus
   Cancel = True
   Exit Sub
End If
If InStr(Me.YourControlName,"/")<>0 Then
    msgbox "Your PO includes illegal characters. Please verify your entry and try again.", vbCritical+vbokonly,"Validation Error"
    Me.YourControlName.SetFocus
    Cancel = True
    Exit Sub
End If


Another option for dealing with the / would be to simply automate replacing / with - using code like
CODE
Me.YourControlName = Replace(Me.YourControlName,"/","-")
theDBguy
Hi Mike,

If there are more than just one illegal character that you have to deal with, take a look at this function in the Wiki's Function Library: Strip Illegal Characters

Just my 2 cents... 2cents.gif
JonSmith
Does no-one else use input masks? I find them very useful and easy for validating data.

Set an input mask to
CODE
000-000000;;" "
and you will be golden.

I also tend to use a little bit of code around the sel.start property aswell so when a use clicks the field they don't end up in the middle of the input mask but its very simple and works perfectly.
DanielPineault
Very good idea JonSmith.
JonSmith
For reference here is the code I mentioned

CODE
Private Sub ControlName_Click()

    If Me.ControlName.Text = "   -         " Then Me.ControlName.SelStart = 0

End Sub


Now this is will only work with the specific input mask I posted earlier, if you use a different input mask you will need to amend the " - " to whatever it is. An easy way to find it is to use
CODE
Debug.Print Me.ControlName.Text
on the controls enter event when the control is empty.
theDBguy
Hi Jon,

QUOTE (JonSmith @ May 26 2012, 03:01 AM) *
Does no-one else use input masks? I find them very useful and easy for validating data.

They do have their uses but I, for one, do not use them for varying reasons.

Just my 2 cents... 2cents.gif
missinglinq
I never use Input Mask, either! It's more complicated than just entering the actual Mask, and most production-type Access users (users that input large amounts of data in a day) complain that they actually slow them down. When using Input Masks, you have to be sure to use code like this to assure that if the user clicks on the Textbox the cursor will go to the beginning of the Field. Otherwise the insert point will be wherever they clicked in, and they'll then have to waste time moving the cursor to the beginning of the Field before they start entering data.

CODE
Private Sub YourTextBoxName_Click()
   Me.YourTextBoxName.SelStart = 0
End Sub


If your Access default for Entering a Field is set to anything other than "Go to
start of field
," also use this

CODE
Private Sub YourTextBoxName_GotFocus()
  Me.YourTextBoxName.SelStart = 0
End Sub


Also use this second if you're going to be distributing your database to multiple machines. That way the users can have the Entering a Field behavior set to their own preference for other DBs.

Linq ;0)>
gemmathehusky
input mask

i usually avoid them, althuogh i find them useful for entering times

a mask of 00:00 accepts a time with no problem.
JonSmith
QUOTE (missinglinq @ May 27 2012, 08:59 PM) *
I never use Input Mask, either! It's more complicated than just entering the actual Mask, and most production-type Access users (users that input large amounts of data in a day) complain that they actually slow them down. When using Input Masks, you have to be sure to use code like this to assure that if the user clicks on the Textbox the cursor will go to the beginning of the Field. Otherwise the insert point will be wherever they clicked in, and they'll then have to waste time moving the cursor to the beginning of the Field before they start entering data.

CODE
Private Sub YourTextBoxName_Click()
   Me.YourTextBoxName.SelStart = 0
End Sub



Linq - Did you see my post with my click code? It works much better then the one you use imo (which I used to use) because it allows the user to partially fill in the value and then click back to a previous part of the string or click in the middle of an existing value. You code means that if they intentionally try to click in the middle of a control they will always get sent to the beginning and have to use the arrow keys to get further in.

Can you give me some examples of the complaints your production-type Access users please as I'd be interested to hear the downsides, from where I am sitting (which is crucially not a data entry position, hence the desire for more info) I can't see how they would slow them down, if they do enter an invalid key (such as pressing the / in a date) Access just ignores it anyway, its not like they have to click a message box or anything?
theDBguy
Hi Jon,

QUOTE (JonSmith @ May 28 2012, 09:56 AM) *
Can you give me some examples of the complaints your production-type Access users please as I'd be interested to hear the downsides, from where I am sitting (which is crucially not a data entry position, hence the desire for more info) I can't see how they would slow them down, if they do enter an invalid key (such as pressing the / in a date) Access just ignores it anyway, its not like they have to click a message box or anything?

Here's one quick example that I can think of, can't say that it's happened to me because, as I said earlier, I also try to avoid using Input Masks (except for "Passwords").

Let's say you have a date field and you decided to use an input mask of, say, "00/00/0000" (sorry if that mask is wrong, like I said, I don't use them), the idea being, you want the user to enter 2-digit month, 2-digit day, and 4-digit year. However, let's say the user needed to input a bunch of records for the today (05/28/2012). If you didn't have an input mask, all they really need to type is something like "5/28." But with the input mask, they would have to hit five extra keys for each record. So, depending on how many records they need to input and how fast they type, the input mask may or may not cause any delay for them.

Just my 2 cents... 2cents.gif
JonSmith
Thanks DBGuy, I can see how that could be an issue. In my current application date fields tend to be on a form with a calendar control (used to filter records) and I use double click behavior to enter the date that is currently displayed that calendar and the +/- keys to increment/decrement (is that a word?) so I don't think I have come across that issue before, plus I don't think the data entry we do works in the same sort of way perhaps. Could you possibly capture the exit event (if that fires before the input validation) and enter the current year if the user doesn't provide it? I might go look into that now.

Can anyone give any other examples that don't use dates?

Edit: I have played around and there are some ways around the lack of year issue with dates by using the forms error event to add it to values missing it. However its abit clunky and probably wouldn't be worth the event. I have found without a mask users sometime missed a digit so for example they enter 28/06/212 (British date order for you Americans tongue.gif), looks like there is no magic solution either way to fix human error.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.