Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 46
Default Text Box : Controlling what the user inputs

Dear All,

I have a user form that has several text boxs that require input. How do I
format these boxes / control what the user inputs into them.

ie on the change sub of the text box I need a control that says

If textbox1.numberformat = "dd-mm-yyyy" Then Next
Else
MsgBox("Please enter date as dd-mm-yyyy")


Furthermore I would also like to format a text box so that percentages can
be entered. At present I have had to highlight to the user that they need to
be entered as a decimal. Is there any way around this?


Thanks in advance

And thanks for all your previous help. Starting to get the basics of this
and put together some 'good' templates.

Kind Regards
Matthew Balch
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,726
Default Text Box : Controlling what the user inputs

You cannot set formatr to textboxes as you can with cells (unfortunately),
and there is no built-in masking either, so you have to either build it
yourself, or check after the event. For instance,

With Me.TextBox1
If Not IsDate(.Text) Then
.SelStart = 0
.SelLength = Len(.Text)
.SetFocus
MsgBox ("Please enter date as dd-mm-yyyy")
End If
End With


For percentages, assuming not greater than 100, you can try

Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
With Me.TextBox1
Debug.Print .Text, KeyAscii
Select Case KeyAscii
Case 48 To 57 'numbers
If (Len(.Text) = 2 And (.Text < "10" Or KeyAscii < 48)) Or
_
Len(.Text) = 3 Then
Beep
KeyAscii = 0
End If
Case Else 'Discard anything else
Beep
KeyAscii = 0
End Select
End With
End Sub


--

HTH

Bob Phillips

(replace xxxx in the email address with gmail if mailing direct)

"Matthew Balch" wrote in message
...
Dear All,

I have a user form that has several text boxs that require input. How do

I
format these boxes / control what the user inputs into them.

ie on the change sub of the text box I need a control that says

If textbox1.numberformat = "dd-mm-yyyy" Then Next
Else
MsgBox("Please enter date as dd-mm-yyyy")


Furthermore I would also like to format a text box so that percentages can
be entered. At present I have had to highlight to the user that they need

to
be entered as a decimal. Is there any way around this?


Thanks in advance

And thanks for all your previous help. Starting to get the basics of this
and put together some 'good' templates.

Kind Regards
Matthew Balch



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 46
Default Text Box : Controlling what the user inputs

Thanks Bob :)

"Bob Phillips" wrote:

You cannot set formatr to textboxes as you can with cells (unfortunately),
and there is no built-in masking either, so you have to either build it
yourself, or check after the event. For instance,

With Me.TextBox1
If Not IsDate(.Text) Then
.SelStart = 0
.SelLength = Len(.Text)
.SetFocus
MsgBox ("Please enter date as dd-mm-yyyy")
End If
End With


For percentages, assuming not greater than 100, you can try

Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
With Me.TextBox1
Debug.Print .Text, KeyAscii
Select Case KeyAscii
Case 48 To 57 'numbers
If (Len(.Text) = 2 And (.Text < "10" Or KeyAscii < 48)) Or
_
Len(.Text) = 3 Then
Beep
KeyAscii = 0
End If
Case Else 'Discard anything else
Beep
KeyAscii = 0
End Select
End With
End Sub


--

HTH

Bob Phillips

(replace xxxx in the email address with gmail if mailing direct)

"Matthew Balch" wrote in message
...
Dear All,

I have a user form that has several text boxs that require input. How do

I
format these boxes / control what the user inputs into them.

ie on the change sub of the text box I need a control that says

If textbox1.numberformat = "dd-mm-yyyy" Then Next
Else
MsgBox("Please enter date as dd-mm-yyyy")


Furthermore I would also like to format a text box so that percentages can
be entered. At present I have had to highlight to the user that they need

to
be entered as a decimal. Is there any way around this?


Thanks in advance

And thanks for all your previous help. Starting to get the basics of this
and put together some 'good' templates.

Kind Regards
Matthew Balch




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
Forcing User inputs apache007 Excel Discussion (Misc queries) 1 February 6th 10 05:11 PM
Locking Cells when user inputs data NervousFred Excel Discussion (Misc queries) 0 August 1st 08 09:34 PM
Extend Border As User Inputs New Rows Paperback Writer Excel Discussion (Misc queries) 1 December 1st 06 02:58 PM
Controlling user environment Colinhp Excel Programming 3 July 10th 06 01:10 PM
If the user inputs lower case y/n answer How do I convert automat. jhg1226 Excel Discussion (Misc queries) 2 February 10th 05 02:26 PM


All times are GMT +1. The time now is 10:37 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"