Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Validation Rule Help

Status
Not open for further replies.

ssatech

Technical User
Feb 27, 2003
361
IE
I am drawing a blank at the moment!
I need to set a validation rule in a table so that no spaces are allowed in the text field during entry.

e.g. 01612561258 and not 016 1256 1258

Any help appreciated,
 
If you are sure about the number of digits then you can use an input mask AAAAAAAAAA as per the count of digits.
for more about input mask search for "Input mask syntax and examples" in help file

________________________________________
Zameer Abdulla
Visit Me
Minds are like parachutes. They only function when they are open. -Sir James Dewar (1877-1925)
 
Thanks Zmr,
I have done this but I think I need to code this on the form to inform the user that the data is incorrectly entered if it entered like this:

016 1256 1258 instead of this 01612561258

I have coded this on the form but it only works for numbers. i need to code it somehow if either number or text is entered.

Dim i As Integer, flag As String
Cancel = 0

For i = 1 To Len(Me.BillOfLading)
flag = Mid(Me.BillOfLading, i, 1)
If flag <> "" And flag <> "1" And flag <> "2" And flag <> "3" And flag <> "4" And flag <> "5" And flag <> "6" And flag <> "7" And flag <> "8" And flag <> "9" And flag <> "0" Then
Cancel = -1
MsgBox "Invalid entry, characters must not be spaced"
Exit For
End If

Next
End Sub


Any ideas, perhaps I should post this in the Forms forum.
 
Here is a quick example of this. I am sure I have taken this from TT most probably from RoyVidar's post. You will be able to figure out from this.
Code:
Private Sub Amount_KeyDown(KeyCode As Integer, Shift As Integer)
'Dim KeyCode As Integer
Select Case KeyCode
    Case vbKeyNumpad0 To vbKeyNumpad9, vbKey0 To vbKey9, vbKeyDecimal
        ' if control prior to entering this key, alredy has
        ' a length of 8, disallow new number
        If Len(Me!Amount.Text) >= 8 Then
             KeyCode = 0 ' cancel keystroke
        End If
    Case vbKeyDelete, vbKeyBack, vbKeyLeft, vbKeyRight, vbKeyTab
        ' do nothing, they're allowed
    Case Else ' disable the rest
        KeyCode = 0 ' cancel keystroke
End Select
End Sub

________________________________________
Zameer Abdulla
Visit Me
Minds are like parachutes. They only function when they are open. -Sir James Dewar (1877-1925)
 
Zameer,

Thanks for your input.
I'll have to try to redue the code to accept text entry.
 
Zameer,
Thanks for for RoyVidar's post. The code worked perfect with the additional vbKeys

Case vbKeyNumpad0 To vbKeyNumpad9, vbKey0 To vbKey9, vbKeyDecimal, vbKeyA To vbKeyZ

You were a great help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top