Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
damorrison
 
Posts: n/a
Default Not all boxes have been entered

I have a UserForm with several List and text boxes, is it possible to
have a message pop up, if the user clicks ok
but hasn't touched all the boxes yet
and the message box saying so and which box has been missed

  #2   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson
 
Posts: n/a
Default Not all boxes have been entered

How about an alternative?

Disable the Ok button until all the textboxes and listboxes have something
entered/selected.

I created a userform with
5 textboxes
2 listboxes (multiselect)
1 label (for messages)
2 command buttons (ok and cancel).

This is the code that I had behind the userform:

Option Explicit
Dim BlkProc As Boolean
Private Sub CommandButton1_Click()
Unload Me
End Sub
Private Sub CommandButton2_Click()
MsgBox "Congratulations--you filled in all the boxes!"
End Sub
Private Sub ListBox1_change()
Call ChkOkBTN
End Sub
Private Sub ListBox2_change()
Call ChkOkBTN
End Sub
Private Sub TextBox1_Change()
Call ChkOkBTN
End Sub
Private Sub TextBox2_Change()
Call ChkOkBTN
End Sub
Private Sub TextBox3_Change()
Call ChkOkBTN
End Sub
Private Sub TextBox4_Change()
Call ChkOkBTN
End Sub
Private Sub TextBox5_Change()
Call ChkOkBTN
End Sub
Private Sub UserForm_Initialize()
Dim iCtr As Long

For iCtr = 1 To 10
Me.ListBox1.AddItem "hi" & iCtr
Me.ListBox2.AddItem "Bye" & iCtr
Next iCtr

With Me.CommandButton1
.Caption = "Cancel"
.Enabled = True
End With

With Me.CommandButton2
.Caption = "Ok"
.Enabled = False
End With

BlkProc = True
With Me.ListBox1
.MultiSelect = fmMultiSelectMulti
.Tag = "Hello Listbox"
End With
With Me.ListBox2
.MultiSelect = fmMultiSelectMulti
.Tag = "Goodbye ListBox"
End With
BlkProc = False

Me.TextBox1.Tag = "textbox #1 description here"
Me.TextBox2.Tag = "textbox #2 description here"
Me.TextBox3.Tag = "textbox #3 description here"
Me.TextBox4.Tag = "textbox #4 description here"
Me.TextBox5.Tag = "textbox #5 description here"

Me.Label1.Caption = "Please fill in: " & Me.TextBox1.Tag

End Sub
Sub ChkOkBTN()
Dim ctrl As Control
Dim iCtr As Long
Dim OkBtnEnabled As Boolean
Dim ListBoxHasSelection As Boolean
Dim CtrlWithProblem As String

If BlkProc = True Then Exit Sub

OkBtnEnabled = True
For Each ctrl In Me.Controls
If TypeOf ctrl Is MSForms.TextBox Then
If ctrl.Value = "" Then
OkBtnEnabled = False
CtrlWithProblem = ctrl.Tag
Exit For
End If
Else
If TypeOf ctrl Is MSForms.ListBox Then
ListBoxHasSelection = False
For iCtr = 1 To ctrl.ListCount
If ctrl.Selected(iCtr) = True Then
ListBoxHasSelection = True
Exit For
End If
Next iCtr
If ListBoxHasSelection = False Then
OkBtnEnabled = False
CtrlWithProblem = ctrl.Tag
Exit For
End If
End If
End If
Next ctrl

If OkBtnEnabled = False Then
Me.Label1.Caption = "Please fill in: " & CtrlWithProblem
Else
Me.Label1.Caption = ""
End If

Me.CommandButton2.Enabled = OkBtnEnabled

End Sub


damorrison wrote:

I have a UserForm with several List and text boxes, is it possible to
have a message pop up, if the user clicks ok
but hasn't touched all the boxes yet
and the message box saying so and which box has been missed


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.misc
damorrison
 
Posts: n/a
Default Not all boxes have been entered

Okay Dave, I will put work with that,
Thanks

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
Questions on combo boxes and list boxes. Marc New Users to Excel 1 March 14th 06 09:40 AM
Boxes in Forms PaulW Excel Discussion (Misc queries) 0 March 10th 06 03:18 PM
Is there a way to add up check boxes strider11580 Excel Discussion (Misc queries) 2 January 24th 06 04:37 AM
Check boxes - when one box is checked, I want a 2nd box to auto ch Russell-stanely Excel Discussion (Misc queries) 2 July 1st 05 08:52 PM
Excel 2002 Will Not Print Text Boxes Mark Excel Discussion (Misc queries) 3 April 16th 05 12:03 AM


All times are GMT +1. The time now is 05:53 PM.

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"