Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 290
Default Spaces in Textbox

Hi All,

I pose what may be a tricky question,

I want to error when textboxes have just spaces in, I can disallow
spaces with code I found on here by Darrin Henshaw but here is the
tricky part,

What I want in the textbox may have two parts, like first name then
surname with a space inbetween. (Fname Lname) or two spaces (Some
Company Ltd).

With Darrins solution (which I will post below) he has managed to stop
ALL spaces from being entered in the textbox, But I want to allow
spaces IF there is something in the textbox that isnt a space (as
above)......

or.....if you could envisage a validation that flagged up just spaces
and disallowed this (all my validation is on my 'submit' button) then
this might be easier, I dont know how to check for this

Any help would be much appreciated

(I will post what I found on here that im trying to adapt below)

Duncan

Private Sub EName_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal
Shift As Integer)
With Me.EName
Select Case True
Case (KeyCode = 97 And KeyCode < 122)
'exit quietly
Case (KeyCode = 48 And KeyCode < 57)
'exit quietly
Case (KeyCode = 65 And KeyCode < 90)
'exit quietly
Case KeyCode = 9 'tab
Case KeyCode = 8 'backspace
If Len(.Text) 0 Then
.Text = Left(.Text, Len(.Text) - 1)
End If
KeyCode = 0
Case Else
KeyCode = 0
Beep
End Select
End With
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Spaces in Textbox

Why not just give the user a text box for each separate piece of information
they need to enter ?
More simple for them and you.

NickHK

"Duncan" wrote in message
oups.com...
Hi All,

I pose what may be a tricky question,

I want to error when textboxes have just spaces in, I can disallow
spaces with code I found on here by Darrin Henshaw but here is the
tricky part,

What I want in the textbox may have two parts, like first name then
surname with a space inbetween. (Fname Lname) or two spaces (Some
Company Ltd).

With Darrins solution (which I will post below) he has managed to stop
ALL spaces from being entered in the textbox, But I want to allow
spaces IF there is something in the textbox that isnt a space (as
above)......

or.....if you could envisage a validation that flagged up just spaces
and disallowed this (all my validation is on my 'submit' button) then
this might be easier, I dont know how to check for this

Any help would be much appreciated

(I will post what I found on here that im trying to adapt below)

Duncan

Private Sub EName_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal
Shift As Integer)
With Me.EName
Select Case True
Case (KeyCode = 97 And KeyCode < 122)
'exit quietly
Case (KeyCode = 48 And KeyCode < 57)
'exit quietly
Case (KeyCode = 65 And KeyCode < 90)
'exit quietly
Case KeyCode = 9 'tab
Case KeyCode = 8 'backspace
If Len(.Text) 0 Then
.Text = Left(.Text, Len(.Text) - 1)
End If
KeyCode = 0
Case Else
KeyCode = 0
Beep
End Select
End With
End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 290
Default Spaces in Textbox

ummm......please explain Nick?

Sorry but I dont really understand your answer.

Duncan


NickHK wrote:
Why not just give the user a text box for each separate piece of information
they need to enter ?
More simple for them and you.

NickHK

"Duncan" wrote in message
oups.com...
Hi All,

I pose what may be a tricky question,

I want to error when textboxes have just spaces in, I can disallow
spaces with code I found on here by Darrin Henshaw but here is the
tricky part,

What I want in the textbox may have two parts, like first name then
surname with a space inbetween. (Fname Lname) or two spaces (Some
Company Ltd).

With Darrins solution (which I will post below) he has managed to stop
ALL spaces from being entered in the textbox, But I want to allow
spaces IF there is something in the textbox that isnt a space (as
above)......

or.....if you could envisage a validation that flagged up just spaces
and disallowed this (all my validation is on my 'submit' button) then
this might be easier, I dont know how to check for this

Any help would be much appreciated

(I will post what I found on here that im trying to adapt below)

Duncan

Private Sub EName_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal
Shift As Integer)
With Me.EName
Select Case True
Case (KeyCode = 97 And KeyCode < 122)
'exit quietly
Case (KeyCode = 48 And KeyCode < 57)
'exit quietly
Case (KeyCode = 65 And KeyCode < 90)
'exit quietly
Case KeyCode = 9 'tab
Case KeyCode = 8 'backspace
If Len(.Text) 0 Then
.Text = Left(.Text, Len(.Text) - 1)
End If
KeyCode = 0
Case Else
KeyCode = 0
Beep
End Select
End With
End Sub


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Spaces in Textbox

Give the user 2 text boxes; one for First name, one for surname.
Then is much clearer what is expected.

NickHK

"Duncan" wrote in message
ups.com...
ummm......please explain Nick?

Sorry but I dont really understand your answer.

Duncan


NickHK wrote:
Why not just give the user a text box for each separate piece of

information
they need to enter ?
More simple for them and you.

NickHK

"Duncan" wrote in message
oups.com...
Hi All,

I pose what may be a tricky question,

I want to error when textboxes have just spaces in, I can disallow
spaces with code I found on here by Darrin Henshaw but here is the
tricky part,

What I want in the textbox may have two parts, like first name then
surname with a space inbetween. (Fname Lname) or two spaces (Some
Company Ltd).

With Darrins solution (which I will post below) he has managed to stop
ALL spaces from being entered in the textbox, But I want to allow
spaces IF there is something in the textbox that isnt a space (as
above)......

or.....if you could envisage a validation that flagged up just spaces
and disallowed this (all my validation is on my 'submit' button) then
this might be easier, I dont know how to check for this

Any help would be much appreciated

(I will post what I found on here that im trying to adapt below)

Duncan

Private Sub EName_KeyDown(ByVal KeyCode As MSForms.ReturnInteger,

ByVal
Shift As Integer)
With Me.EName
Select Case True
Case (KeyCode = 97 And KeyCode < 122)
'exit quietly
Case (KeyCode = 48 And KeyCode < 57)
'exit quietly
Case (KeyCode = 65 And KeyCode < 90)
'exit quietly
Case KeyCode = 9 'tab
Case KeyCode = 8 'backspace
If Len(.Text) 0 Then
.Text = Left(.Text, Len(.Text) - 1)
End If
KeyCode = 0
Case Else
KeyCode = 0
Beep
End Select
End With
End Sub




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 290
Default Spaces in Textbox

ah, I see what you mean now, but these boxes may contain up to 4 words.

Such as: "A1 Technology Services Ltd"

and I dont really want 4 boxes on my form....

Duncan



NickHK wrote:

Give the user 2 text boxes; one for First name, one for surname.
Then is much clearer what is expected.

NickHK

"Duncan" wrote in message
ups.com...
ummm......please explain Nick?

Sorry but I dont really understand your answer.

Duncan


NickHK wrote:
Why not just give the user a text box for each separate piece of

information
they need to enter ?
More simple for them and you.

NickHK

"Duncan" wrote in message
oups.com...
Hi All,

I pose what may be a tricky question,

I want to error when textboxes have just spaces in, I can disallow
spaces with code I found on here by Darrin Henshaw but here is the
tricky part,

What I want in the textbox may have two parts, like first name then
surname with a space inbetween. (Fname Lname) or two spaces (Some
Company Ltd).

With Darrins solution (which I will post below) he has managed to stop
ALL spaces from being entered in the textbox, But I want to allow
spaces IF there is something in the textbox that isnt a space (as
above)......

or.....if you could envisage a validation that flagged up just spaces
and disallowed this (all my validation is on my 'submit' button) then
this might be easier, I dont know how to check for this

Any help would be much appreciated

(I will post what I found on here that im trying to adapt below)

Duncan

Private Sub EName_KeyDown(ByVal KeyCode As MSForms.ReturnInteger,

ByVal
Shift As Integer)
With Me.EName
Select Case True
Case (KeyCode = 97 And KeyCode < 122)
'exit quietly
Case (KeyCode = 48 And KeyCode < 57)
'exit quietly
Case (KeyCode = 65 And KeyCode < 90)
'exit quietly
Case KeyCode = 9 'tab
Case KeyCode = 8 'backspace
If Len(.Text) 0 Then
.Text = Left(.Text, Len(.Text) - 1)
End If
KeyCode = 0
Case Else
KeyCode = 0
Beep
End Select
End With
End Sub





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Spaces in Textbox

Duncan,
Validate after the input.
You can LTrim/RTrim and Replace multiple space with a single.

NickHK

"Duncan" wrote in message
oups.com...
ah, I see what you mean now, but these boxes may contain up to 4 words.

Such as: "A1 Technology Services Ltd"

and I dont really want 4 boxes on my form....

Duncan



NickHK wrote:

Give the user 2 text boxes; one for First name, one for surname.
Then is much clearer what is expected.

NickHK

"Duncan" wrote in message
ups.com...
ummm......please explain Nick?

Sorry but I dont really understand your answer.

Duncan


NickHK wrote:
Why not just give the user a text box for each separate piece of

information
they need to enter ?
More simple for them and you.

NickHK

"Duncan" wrote in message
oups.com...
Hi All,

I pose what may be a tricky question,

I want to error when textboxes have just spaces in, I can disallow
spaces with code I found on here by Darrin Henshaw but here is the
tricky part,

What I want in the textbox may have two parts, like first name

then
surname with a space inbetween. (Fname Lname) or two spaces (Some
Company Ltd).

With Darrins solution (which I will post below) he has managed to

stop
ALL spaces from being entered in the textbox, But I want to allow
spaces IF there is something in the textbox that isnt a space (as
above)......

or.....if you could envisage a validation that flagged up just

spaces
and disallowed this (all my validation is on my 'submit' button)

then
this might be easier, I dont know how to check for this

Any help would be much appreciated

(I will post what I found on here that im trying to adapt below)

Duncan

Private Sub EName_KeyDown(ByVal KeyCode As MSForms.ReturnInteger,

ByVal
Shift As Integer)
With Me.EName
Select Case True
Case (KeyCode = 97 And KeyCode < 122)
'exit quietly
Case (KeyCode = 48 And KeyCode < 57)
'exit quietly
Case (KeyCode = 65 And KeyCode < 90)
'exit quietly
Case KeyCode = 9 'tab
Case KeyCode = 8 'backspace
If Len(.Text) 0 Then
.Text = Left(.Text, Len(.Text) - 1)
End If
KeyCode = 0
Case Else
KeyCode = 0
Beep
End Select
End With
End Sub





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
how do I remove leading spaces and leave the remianing spaces w Debi Excel Worksheet Functions 6 February 28th 07 03:29 PM
HELP! I Lost The Ability To Advance From TextBox To TextBox With the ENTER Or The TAB Keys Minitman[_4_] Excel Programming 0 February 22nd 05 08:50 PM
Textbox Bug? Missing/delayed update of textbox filled via VBA MarcM Excel Programming 0 November 4th 04 05:47 PM
Textbox Bug? Missing/delayed update of textbox filled via VBA MarcM Excel Programming 0 November 4th 04 05:43 PM
limit textbox to numbers or spaces? CAA[_14_] Excel Programming 2 January 22nd 04 01:47 PM


All times are GMT +1. The time now is 06:13 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"