Home |
Search |
Today's Posts |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Instead of using a message box to tell the user what's going on, I used a label
on the userform. I want that label "hidden" when the userform starts--so I just make the caption blank (""). "Jean-Pierre D via OfficeKB.com" wrote: Hi Dave, Thanks for your input. Can you explain the Me.Label1.Caption = "" part of your code please ? Thanks, Pierre Dave Peterson wrote: I created a userform with 10 textboxes, 1 label and 2 commandbuttons. This is the code that's behind the userform: Option Explicit Private Sub UserForm_Initialize() Me.Label1.Caption = "" End Sub Private Sub CommandButton1_Click() Unload Me End Sub Private Sub CommandButton2_Click() Dim OkToContinue As Boolean OkToContinue = CheckTextBoxes If OkToContinue = False Then Exit Sub End If MsgBox "do the real work here" End Sub Private Sub TextBox1_KeyPress(ByVal keyascii As MSForms.ReturnInteger) Call CheckKeys(1, keyascii) End Sub Private Sub TextBox2_KeyPress(ByVal keyascii As MSForms.ReturnInteger) Call CheckKeys(2, keyascii) End Sub Private Sub TextBox3_KeyPress(ByVal keyascii As MSForms.ReturnInteger) Call CheckKeys(3, keyascii) End Sub Private Sub TextBox4_KeyPress(ByVal keyascii As MSForms.ReturnInteger) Call CheckKeys(4, keyascii) End Sub Private Sub TextBox5_KeyPress(ByVal keyascii As MSForms.ReturnInteger) Call CheckKeys(5, keyascii) End Sub Private Sub TextBox6_KeyPress(ByVal keyascii As MSForms.ReturnInteger) Call CheckKeys(6, keyascii) End Sub Private Sub TextBox7_KeyPress(ByVal keyascii As MSForms.ReturnInteger) Call CheckKeys(7, keyascii) End Sub Private Sub TextBox8_KeyPress(ByVal keyascii As MSForms.ReturnInteger) Call CheckKeys(8, keyascii) End Sub Private Sub TextBox9_KeyPress(ByVal keyascii As MSForms.ReturnInteger) Call CheckKeys(9, keyascii) End Sub Private Sub TextBox10_KeyPress(ByVal keyascii As MSForms.ReturnInteger) Call CheckKeys(10, keyascii) End Sub Sub CheckKeys(TBNumber, keyascii) Dim myTB As MSForms.TextBox Dim OkChar As Boolean Set myTB = Me.Controls("textbox" & TBNumber) OkChar = True Select Case keyascii Case Asc("0") To Asc("9") 'ok Case Is = Asc(",") If Len(myTB.Value) - _ Len(Application.Substitute(myTB.Value, ",", "")) 0 Then 'too many decimals OkChar = False End If Case Else OkChar = False End Select If OkChar = False Then keyascii = 0 Beep End If End Sub Function CheckTextBoxes() As Boolean Dim iCtr As Long Dim myTB As MSForms.TextBox Dim AllOk As Boolean AllOk = True For iCtr = 1 To 10 Set myTB = Me.Controls("Textbox" & iCtr) If Len(Trim(myTB)) = 0 Then myTB.SetFocus AllOk = False Exit For End If Next iCtr If AllOk = True Then Me.Label1.Caption = "" Else Me.Label1.Caption = "Please fill in all the textboxes!" End If CheckTextBoxes = AllOk End Function Hi, [quoted text clipped - 13 lines] Thanks, Pierre -- Message posted via OfficeKB.com http://www.officekb.com/Uwe/Forums.a...mming/200509/1 -- Dave Peterson |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Insert Calculated Field (wrong Qty*Price = wrong Amount) | Excel Discussion (Misc queries) | |||
Increase size of a Forms Check Box (click on to enter check mark) | Excel Discussion (Misc queries) | |||
Check if Conditional Format is True or False / Check cell Color | Excel Worksheet Functions | |||
Spell check: advise and advice are used in the wrong context. | Excel Discussion (Misc queries) | |||
Check or a file exist give wrong result | Excel Programming |