PDA

View Full Version : trimming user input data



nathan2314
12-12-2008, 01:32 PM
Hey Guys,
This is probably a easy one but I'm not sure how to do it. It there an easy way to trim all spaces from the user input after they input it. Sometimes, for example, when a user types in a name they will type in " Jefferson" instead of "Jefferson". This messes up querys. Is there some setting I can put in the table design that would easily take care of this?
Appreciate any help!!
:hi:

CreganTur
12-12-2008, 02:00 PM
You can use the Trim() method for VBA. Take a look at it in Access help to see how it works.

Now, if the User is entering this in the parameter dialog box of a parameter query, then that's a horse of a different color. Parameter querys don't have the luxury of data validation because the User input is injected directly into the SQL statement.

To fix this it would be better to have a Form with textboxs that the User can fill in. Then you can use VBA to trim and validate the User's input and then feed the information to the query- how you do this depends on which query type (Action or Select) you are dealing with.

nathan2314
12-12-2008, 02:22 PM
Ok Thanks,
I'm actually having the user input from a form. So I would have to run VBA code every time a user puts data in any of the text fields I have on the Form?
I was hoping there might be a easy setting in the underlying data table that I could set that after the user inputed his data, the underlining data table would just automatically remove preceding blanks. So this wouldn't bother the user with inputting correctly each time.

Thanks for you help!
:)

CreganTur
12-12-2008, 02:33 PM
So I would have to run VBA code every time a user puts data in any of the text fields I have on the Form?

You could set the code to run itself as part of an event. If you want the event to occur at the textbox level, then you could use the trim function as a part of the AfterUpdate event. Or if your form has some sort of 'submit' button you could have it be a part of the button's click event.