Input Mask question

adamburton

Registered User.
Local time
Today, 03:58
Joined
Jan 24, 2003
Messages
75
Really dumb question here. I want to force the entry within a field to not accept spaces. I have looked through the input mask characters but cannot find one that will allow letters/numbers but not spaces.

Anybody point out to me what character I need to use in my input mask?

Thanks,
Adam.
 
I do not know the input mask to not except spaces, but i do know a procedure that when the user moves of the field it would take the spaces out...
 
Use the KeyDown or KeyPress event. Search for those key words and add my user name to the search and you will find plenty of examples on how to trap and prevent specific keystrokes within a text box or form.
 
Thanks both. I think some of your previous messages must have been deleted GHudson as I couldnt seem to find any code within your previous messages. Or maybe Im doing something wrong.

M8, if you could advise on the procedure I would be grateful.

Thanks very much both of you.

Adam.
 
if you use this code, all that you owuld have to do is change FIELD_NAME to your field name within your form.

Code:
Private Sub FIELD_NAME_AfterUpdate()

RemoveSpaces (Me.FIELD_NAME)

End Sub
Function RemoveSpaces(ByVal AlphaNum As Variant)

   Dim Clean As String
   Dim Pos, A_Char$

   Pos = 1
   If IsNull(AlphaNum) Then Exit Function

   For Pos = 1 To Len(AlphaNum)
      A_Char$ = Mid(AlphaNum, Pos, 1)
      If A_Char$ >= "0" And A_Char$ <= "Z" Then
      Clean$ = Clean$ + A_Char$
      End If
   Next Pos

   Me.FIELD_NAME = Clean$

End Function

Any issue let me know.
 
Thanks very much M8. I will give this a try tomorrow.

kind regards,
Adam.
 
You have to use the advance search options to search for a keyword and also a user name. I just did and I found plenty.

This will prevent a user from keying any non numeric or non alpha characters in the text box.

Code:
Private Sub Text0_KeyPress(KeyAscii As Integer)
    
    Select Case KeyAscii
        Case 97 To 122, 65 To 90, 48 To 57, 8 '8 Backspace '32 Space
            KeyAscii = KeyAscii
        Case Else
            MsgBox "Only alpha or numeric characters are allowed.", vbInformation, "Invalid Key"
            KeyAscii = 0 'key nothing
    End Select
    
End Sub
Search the Access VBA help files for ascii and you will find more info on the character codes and the KeyDown and KeyPress events and more.
 
Last edited:
Oops - I was using the normal search.

I will give your code a try now. Thanks very much for your reply.

kind regards,
Adam.
 
It works like an absolute dream!

Thanks very much GHudson!!

kind regards,
Adam.
 
Your welcome.

Another satisfied customer! ;)
 

Users who are viewing this thread

Back
Top Bottom