PDA

View Full Version : ASCii code to allow a space



lifeson
07-24-2007, 04:05 AM
How do I amend the following code to allow a space to be entered and not just numbers?
Private Sub txtMobile_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
Select Case KeyAscii
Case Asc("0") To Asc("9")
Case Asc("-")
If InStr(1, Me.txtMobile.Text, "-") > 0 Or Me.txtMobile.SelStart > 0 Then
KeyAscii = 0
End If
Case Asc(".")
If InStr(1, Me.txtMobile.Text, ".") > 0 Then
KeyAscii = 0
End If
Case Else
KeyAscii = 0
End Select
End Sub

unmarkedhelicopter
07-24-2007, 04:15 AM
Case Asc(" ")

Bob Phillips
07-24-2007, 04:16 AM
Don't know how you want to handle a space



Private Sub txtMobile_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
Select Case KeyAscii
Case Asc("0") To Asc("9")
Case Asc(" ")
Case Asc("-")
If InStr(1, Me.txtMobile.Text, "-") > 0 Or Me.txtMobile.SelStart > 0 Then
KeyAscii = 0
End If
Case Asc(".")
If InStr(1, Me.txtMobile.Text, ".") > 0 Then
KeyAscii = 0
End If
Case Else
KeyAscii = 0
End Select
End Sub

lifeson
07-24-2007, 04:47 AM
I want to allow the user to be able to input a number such as:

01234 567890

unmarkedhelicopter
07-24-2007, 08:53 AM
A Brit on the east coast USA.
Your original code does not prevent you from doing that.
The handling routine around it may though.
You would need to post the handling routine as well so that we can see.
(Sorry but maybe my first reply was too acute.) ;)

lifeson
07-24-2007, 09:06 AM
Sorry, I dont know what you mean about the handling routine:(
I found that bit of code which sits on a user form and works when the text box is amended and is great at only allowing the user to input numbers 0-9
I just wanted a bit of code that allows the user to input 0-9 and a space (like a phone number)

rory
07-24-2007, 09:14 AM
Did you try the code xld provided you?
Regards,
Rory

lifeson
07-24-2007, 09:19 AM
No :bug: :bug:
I had totally missed that post ! - must be going screen blind - time to stop for today

That works fine :bow:

unmarkedhelicopter
07-24-2007, 09:23 AM
Wow ! and it was SO different to mine !!!!

lifeson
07-24-2007, 09:31 AM
:o: Sorry
I did try something like that but must have done asc("")

rory
07-24-2007, 09:33 AM
And I completely missed yours! (Does that make you an unremarkedhelicopter? :) )

unmarkedhelicopter
07-24-2007, 09:42 AM
Story of my life ... don't ask me to make tea !!!!