leopardhawk
Well-known Member
- Joined
- May 31, 2007
- Messages
- 611
- Office Version
- 2016
- Platform
- Windows
Hello forum friends,
I have a comboBox where the user selects M or F for their gender. Currently, if they are going to click the OK command button to execute the form, they MUST make a choice in this comboBox based on my existing code.
I would like to modify the code so that it will allow them to use the OK command button even if the GenderComboBox is left blank. I'm sure there is a way to do this but I haven't been able to figure it out. I greatly appreciate any ideas or suggestions. Thanks!
I should also mention that it's important that the user can only choose M or F and not be able to type in any other characters.
My existing code:
I have a comboBox where the user selects M or F for their gender. Currently, if they are going to click the OK command button to execute the form, they MUST make a choice in this comboBox based on my existing code.
I would like to modify the code so that it will allow them to use the OK command button even if the GenderComboBox is left blank. I'm sure there is a way to do this but I haven't been able to figure it out. I greatly appreciate any ideas or suggestions. Thanks!
I should also mention that it's important that the user can only choose M or F and not be able to type in any other characters.
My existing code:
VBA Code:
Private Sub OKCommandButton_Click()
If UCase(Me.GenderComboBox.Text) = "M" Or UCase(Me.GenderComboBox.Text) = "F" Then
Else
MsgBox "Please select M or F from the list."
Exit Sub
End If
With Sheets(11)
If Not AllmostEmpty(GenderComboBox) Then .Range("F9").Value = GenderComboBox.Value
End With
Unload Me
End Sub