Unbound form - input mask

  • Thread starter Thread starter cwaters
  • Start date Start date
C

cwaters

Guest
To simplify textbox validation on my unbound forms, in my Form_Load event I create an empty recordset based on the table that will be written to, and then I set each textbox's .InputMask property as follows:

...
txtCity.InputMask = String(rsContact!City, "C")
...

This results in a data-driven size limit that matches the field, limiting the user from entering more text than can be stored in the database. This is the closest I've been able to come to imitating the built-in input mask functionality that bound forms provide.

As the end-user tabs into each textbox however, an undesirable (IMO) string of underlines appears as the user types. If the user uses their mouse to click in the textbox and then start typing, the characters appear where they clicked. This is cumbersome and seems to confuse the user. And on multi-line textboxes, words typed in appear on the second line, then jump to the first line when the user presses the spacebar.

I can't help but wonder if there's a better way to handle field validation. What have others found to be of use? And what about non-text fields--say, dates, numerics, and currency? Thanks!

Chris
 
I had a similar problem with a change password form I was working on. The box needed to use input mask of "Password" of course but then business rules dicatated max password size of 10 characters. What i ended up doing is when they would hit the submit button I validated the length of the text field. If it was >10 I would error box the user and reset the fields back to null.

I don't know how you are submitting your information. Maybe you could do something similar in the before update?
 
Thanks. Seems like the best way to handle control validation is in the BeforeUpdate/AfterUpdate event. Since this is an unbound control, I prefer AfterUpdate, since it more accurately reflects when the event is firing--after the user updates the control and tries to change focus to another control.

In VB, I would do a combination of events and the .MaxLength property. That way, I could prevent the user from needlessly entering more characters than are allowed in the table's field--thereby eliminating that check in the validation event, as well as saving the user an annoying dialog box.

Looks like I don't have that option in Access.
 
In the event that validates the data (i.e., AfterUpdate, BeforeUpdate, or even LostFocus), I would like to change the focus to the control containing the offending data. However, when I place the following code in the event:

MsgBox "The text you entered is too large."
txtCity.SetFocus

the user sees the message box, but is *not* placed back in the txtCity control. Any idea why?


Also, if the user presses the OK button, they see the message box, but the code in the OK_Click event (which saves the entered information to the database) executes, attempting to save the invalid information--resulting in a (admittedly trappable) run-time error.

It seems like I need to validate *all* of the data a second time (i.e., in the OK_Click event) before attempting to save to the database. Is that correct?
 

Users who are viewing this thread

Back
Top Bottom