Kevin,
In case you're interested in the "fence at the top" solution, here is some
example code:
Option Explicit
Private Sub UserForm_Initialize()
LoadFromList
LoadOfficeList
LoadPositionList
optStandard.Value = True
CheckOffice
CheckPosition
txtTo.SetFocus
End Sub
Private Sub LoadFromList()
With cboFrom
.AddItem "[SELECT]", 0
.AddItem "From 1", 1
.AddItem "From 2", 2
.ListIndex = 0
End With
End Sub
Private Sub LoadOfficeList()
With cboOffice
.AddItem "[SELECT]", 0
.AddItem "Office 1", 1
.AddItem "Office 2", 2
End With
End Sub
Private Sub LoadPositionList()
With cboPosition
.AddItem "[SELECT]", 0
.AddItem "Position 1", 1
.AddItem "Position 2", 2
End With
End Sub
Private Sub optStandard_Change()
CheckOKButton
End Sub
Private Sub txtTo_Change()
CheckOKButton
End Sub
Private Sub cboFrom_Change()
CheckOKButton
End Sub
Private Sub txtTitle_Change()
CheckOKButton
End Sub
Private Sub txtSubject_Change()
CheckOKButton
End Sub
Private Sub boxRecipient_Change()
CheckOffice
CheckPosition
CheckOKButton
End Sub
Private Sub CheckOffice()
If boxRecipient.Value = True Then EnableOffice Else DisableOffice
End Sub
Private Sub EnableOffice()
With cboOffice
.Enabled = True
.Locked = False
.TabStop = False
.BackColor = &H80000005
.ListIndex = 0
End With
End Sub
Private Sub DisableOffice()
With cboOffice
.Enabled = False
.Locked = True
.TabStop = False
.BackColor = &H8000000F
.ListIndex = -1
End With
End Sub
Private Sub CheckPosition()
If boxRecipient.Value = True Then EnablePosition Else DisablePosition
End Sub
Private Sub EnablePosition()
With cboPosition
.Enabled = True
.Locked = False
.TabStop = False
.BackColor = &H80000005
.ListIndex = 0
End With
End Sub
Private Sub DisablePosition()
With cboPosition
.Enabled = False
.Locked = True
.TabStop = False
.BackColor = &H8000000F
.ListIndex = -1
End With
End Sub
Private Sub cboOffice_Change()
CheckOKButton
End Sub
Private Sub cboPosition_Change()
CheckOKButton
End Sub
Private Sub CheckOKButton()
Dim boolToOK As Boolean
Dim boolFromOK As Boolean
Dim boolTitleOK As Boolean
Dim boolSubjectOK As Boolean
Dim boolOfficeOK As Boolean
Dim boolPositionOK As Boolean
If optStandard.Value = True Then
boolToOK = fcnCheckTextBoxValue(txtTo.Value)
boolFromOK = fcnCheckComboBoxValue(cboFrom.ListIndex)
boolTitleOK = fcnCheckTextBoxValue(txtTitle.Value)
boolSubjectOK = fcnCheckTextBoxValue(txtSubject.Value)
If boxRecipient.Value = True Then
boolOfficeOK = fcnCheckComboBoxValue(cboOffice.ListIndex)
boolPositionOK = fcnCheckComboBoxValue(cboPosition.ListIndex)
Else
boolOfficeOK = True
boolPositionOK = True
End If
Else
boolToOK = True
boolFromOK = True
boolTitleOK = True
boolSubjectOK = True
boolOfficeOK = True
boolPositionOK = True
End If
If boolToOK = True And boolFromOK = True And boolTitleOK = True _
And boolSubjectOK = True And boolOfficeOK = True And boolPositionOK =
True _
Then EnableOKButton Else DisableOKButton
End Sub
Private Sub EnableOKButton()
btnCancel.Default = False
With btnOK
.Enabled = True
.Locked = False
.TabStop = True
.Default = True
End With
End Sub
Private Sub DisableOKButton()
With btnOK
.Enabled = False
.Locked = True
.TabStop = False
.Default = False
End With
btnCancel.Default = False
End Sub
Private Function fcnCheckTextBoxValue(InputValue As String) As Boolean
If InputValue <> "" Then fcnCheckTextBoxValue = True Else
fcnCheckTextBoxValue = False
End Function
Private Function fcnCheckComboBoxValue(InputValue As Integer) As Boolean
If InputValue > 0 Then fcnCheckComboBoxValue = True Else
fcnCheckComboBoxValue = False
End Function
Private Sub btnOK_Click()
UserForm1.Hide
'Do whatever else needs to be done with the values from the UserForm
Unload UserForm1
End Sub
Private Sub btnCancel_Click()
Dim myResult As Integer
myResult = MsgBox("Are you sure you want to cancel?", vbYesNo, "Cancel
Doc")
If myResult = 6 Then
UserForm1.Hide
ActiveDocument.Close wdDoNotSaveChanges
End If
End Sub
A bit more meat on these bones with things like:
* UserForm initialisation code for loading the ComboBox lists
* procedures for enabling / disabling controls
* a safety net on the 'Cancel' button Click event
There should be plenty here to help you on your way.
--
Cheers!
Gordon
Uninvited email contact will be marked as SPAM and ignored. Please post all
follow-ups to the newsgroup.
Gordon Bentley-Mix said:
Kevin,
Assuming a UserForm called 'UserForm1' and a CommandButton called 'btnOK'
I'd probably do something like this:
Option Explicit
Dim boolToOK As Boolean
Dim boolFromOK As Boolean
Dim boolTitleOK As Boolean
Dim boolSubjectOK As Boolean
Dim boolOfficeOK As Boolean
Dim boolPositionOK As Boolean
Private Sub btnOK_Click()
If optStandard.Value = True Then
boolToOK = fcnCheckTextBoxValue(txtTo.Value)
boolFromOK = fcnCheckComboBoxValue(cboFrom.ListIndex)
boolTitleOK = fcnCheckTextBoxValue(txtTitle.Value)
boolSubjectOK = fcnCheckTextBoxValue(txtSubject.Value)
If boxRecipient.Value = True Then
boolOfficeOK = fcnCheckComboBoxValue(cboOffice.ListIndex)
boolPositionOK = fcnCheckComboBoxValue(cboPosition.ListIndex)
Else
boolOfficeOK = True
boolPositionOK = True
End If
If boolToOK = False Or boolFromOK = False Or boolTitleOK = False _
Or boolSubjectOK = False Or boolOfficeOK = False Or boolPositionOK =
False Then
MsgBox fcnBuildMessage
Else
UserForm1.Hide
'Do whatever else needs to be done with the values from the
UserForm
Unload UserForm1
End If
Else
UserForm1.Hide
'Do whatever else needs to be done with the values from the UserForm
Unload UserForm1
End If
End Sub
Private Function fcnCheckTextBoxValue(InputValue As String) As Boolean
If InputValue <> "" Then fcnCheckTextBoxValue = True Else
fcnCheckTextBoxValue = False
End Function
Private Function fcnCheckComboBoxValue(InputValue As Integer) As Boolean
If InputValue > 0 Then fcnCheckComboBoxValue = True Else
fcnCheckComboBoxValue = False
End Function
Private Function fcnBuildMessage() As String
Dim strMessage As String
strMessage = "Please make a selection for the following fields:" & vbCr
If boolToOK = False Then strMessage = strMessage & vbCr & " > Office"
If boolFromOK = False Then strMessage = strMessage & vbCr & " > From"
If boolTitleOK = False Then strMessage = strMessage & vbCr & " > Title"
If boolSubjectOK = False Then strMessage = strMessage & vbCr & " >
Subject"
If boolOfficeOK = False Then strMessage = strMessage & vbCr & " >
Office"
If boolPositionOK = False Then strMessage = strMessage & vbCr & " >
Position"
fcnBuildMessage = strMessage
End Function
(I'd also have a CommandButton called 'btnCancel' with Click event code like
this:
Private Sub btnCancel_Click()
UserForm1.Hide
ActiveDocument.Close wdDoNotSaveChanges
End Sub
And I'm sure you probably do too.)
HOWEVER...
Being a "fence at the top of the cliff" kind of guy, I'd probably approach