LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 48
Default Help with code restricting TextBox entry

1st off, I can't believe all this can't be handled within the TextBox
Properties selections. I've looked, but can't see anything on this.

This is something I’ve had help on, but I’m trying to tweak it to get
just what I want.
What I’m trying to do is to require the user to enter a number in
TextBox6, and the user cannot leave it blank.
Here’s what I have so far to help in this:

‘This takes care to not allow an alpha to be entered in TextBox6. This
works fine.
Private Sub TextBox6_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
Select Case KeyAscii
Case 8, 9, 27, 45, 46, 48 To 57
Case Else
Beep
KeyAscii = 0
End Select
End Sub

This part below is what I’m having a problem with. This makes sure
TextBox6 is not left blank. It works fine, except that I would like to
let the user Cancel the whole UserForm routine if he wants. Maybe he
doesn’t have a number to enter for TextBox6 at the time, and would
rather start over after getting the required data.
For right now, this code goes in a continuous loop that requires the
user to enter a number in this box before it will allow the user to do
ANYTHING. Even the Cancel button (see below) will not work until a
number is entered in TextBox6. The only way to get out of the loop is
to enter any number in the box, THEN the Cancel button will work.
‘HOWEVER, if I take out the line Cancel=True, or change it to False,
then the message comes up when TextBox6 is left blank, but, ‘after
hitting OK for the MsgBox reminder, the cursor goes to the next box as
if this whole restriction never applied.
‘In short, I need the requirement that the user enter a number in
TextBox6, but the user must be able to click the Cancel button, too.


Private Sub TextBox6_Exit(ByVal Cancel As MSForms.ReturnBoolean)
‘Keeps user from leaving TextBox6 blank.
With Worksheets("Official list")
If TextBox6.Text = "" Then
MsgBox "This box must have a numeric value. .“
TextBox6.Text = Clear
Cancel = True
End If
End With
End Sub


This is the Cancel button referenced above.
Private Sub CommandButton2_Click()
'CANCEL button.
Unload UserForm4
Worksheets("Menu").Activate
End Sub


NOTE: I would rather handle all this with code specific to
instructions for TextBox6
I’m going to set up similar restrictions (but not the same) for other
textboxes in this userform.
So, I would rather the coding for the OK and Cancel buttons be left
out of all this, if that makes any sense.

I hope this is clear enough for someone to help me. I appreciate it.
Thanks
j.o.
 
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
Restricting entry scubas Excel Worksheet Functions 1 January 11th 10 02:34 PM
Restricting Duplicate Entry Rajat Excel Worksheet Functions 5 November 7th 06 03:00 AM
Restricting entry in B1 on the basis of entry in A1 Stilla Excel Worksheet Functions 7 December 3rd 05 09:17 PM
Restricting entry in B1 on the basis of entry in A1 Biff Excel Worksheet Functions 0 December 3rd 05 03:41 AM
Text Box - Restricting Entry Paul W Smith[_3_] Excel Programming 2 July 31st 04 12:25 AM


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

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

About Us

"It's about Microsoft Excel"