Donate SIGN UP

Microsoft Access 2000

Avatar Image
NickleArse | 10:02 Thu 10th Apr 2003 | Technology
8 Answers
If I have a text field in a table is it possible to have a validation rule to ensure the field contains no spaces?
Gravatar

Answers

1 to 8 of 8rss feed

Best Answer

No best answer has yet been selected by NickleArse. Once a best answer has been selected, it will be shown here.

For more on marking an answer as the "Best Answer", please visit our FAQ.
What sort of data will be going into this field ? Will it always be the same length ? Also will data entry be via the table or from a form ?
Question Author
It will be vehicle registration details. So will not always be the same length (Private Plates etc...). It will be inputted via a form. I thought I would have a problem with reports searching for a registration if some people used spaces and some didn't but it seems to be working ok???
It is simpler to do this in VBA

Paste this code into the BeforeUpdate Event code window...

If IsNull(txtReg) Then
Exit Sub
End If

If InStr(1, txtReg, " ") > 0 Then
MsgBox "Please do not include spaces ", vbOKOnly, "Invalid Reg Number"
Cancel = True
End If


Adjust txtReg to be whatever you named that field and that should do the trick for you
Question Author
Thanks rekstout. I am no expert at VBA but your answer makes sense, I will give it a try. Cheers
Question Author
Yep, tried it and it works a treat. Thanks again.
You could also try this... Create an event procedure for the on key press event for the text box on your form. Paste in this code (where test1 is the name of your text box) Private Sub test1_KeyPress(KeyAscii As Integer) If KeyAscii = 32 Then Beep KeyAscii = 0 End If End Sub
Sorry if that appears a bit jumbled !! Hope you get the gist of it !!
Question Author
Ok, thanks Rinky Tink

1 to 8 of 8rss feed

Do you know the answer?

Microsoft Access 2000

Answer Question >>