PDA

View Full Version : Exit User Form Button



leaf
12-13-2016, 02:04 AM
Hello everybody,

I'm new here but I've seen You guys have a lot of konwledge with VBA and maybe You would help me :)
I have got userform like below.
17826
After pressing "Enter" cursor automaticly goes down from ID_TextBox to Indeksy_ComboBox where is one IF function (must be there). Here comes my problem.
I would like to have possibility to press Exit_CommandButton at anytime. Now it is impossible, untill i put 7 characters into Indeksy_ComboBox.
Once again, cursor goes to ComboBox and it requires 7 characters, until any other action is possible (MsgBox appears).
I hope i explained it well :)
17827
I have got code like below.


Private Sub Indeksy_ComboBox_Exit(ByVal Cancel As MSForms.ReturnBoolean)


If Len(Indeksy_ComboBox.Value) < 7 Then
MsgBox "Insert apropriate value"
Cancel = True
End If


End Sub

Private Sub Exit_CommandButton_Click()
Application.DisplayAlerts = False
Unload Me


End Sub




Do You have any idea how to solve it?
Additional If function in Indeksy_ComboBox_Exit Sub?

Thank You in advance!

Kenneth Hobs
12-13-2016, 07:08 AM
If Len(Indeksy_ComboBox.Value) < 7 And Len(Indeksy_ComboBox.Value) <> 0 Then

leaf
12-13-2016, 07:44 AM
Thank You Kenneth for answer.
Your solution is actualy working, but now user can go further(it is not the end of this user form) without any input in Indeksy_ComboBox. It is not acceptable :)

Kenneth Hobs
12-13-2016, 07:59 AM
Then you have no reason to change? You are not a cake and eat it to sort of person are you?

I guess you can do the original IF in the Exit button but then you have to deal with closing the Userform via the X in upper right, ESC, and Alt+F4 exits.

SamT
12-13-2016, 09:52 AM
Dim IndeksyGotowy As Boolean 'At top of Code page


Private Sub Indeksy_ComboBox_Exit(ByVal Cancel As MSForms.ReturnBoolean)
IndeksyGotowy = False

If Len(Indeksy_ComboBox.Value) =0 Then Exit Sub

If Len(Indeksy_ComboBox.Value) < 7 Then
MsgBox "Insert apropriate value"
Cancel = True
Exit Sub
End If

IndeksyGotowy = True

End Sub

In all other Controls but not Exit button

Sub Control_Click()
If Not IndeksyGotowy Then Indeksy_ComboBox.SetFocus
'
'
'
'
End Sub