Setfocus vba to combobox

Pookiemeister

Well-known Member
Joined
Jan 6, 2012
Messages
626
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
Code:
Private Sub cmbSDPFLine_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Dim rtn_ans1 As String
    If cmbSDPFLine.Value = "" Then
    rtn_ans1 = MsgBox("Please select a production line.", vbOKOnly + vbExclamation & "Please Select Production Line")
End If
Select Case rtn_ans1
Case 1
        cmbSDPFLine.SetFocus
End Select
End Sub
What I'm trying to do is very simple, so I thought. All I want to do is when the user exits the combobox without selecting anything then the messagebox appears, which it does, when the user clicks the ok button it returns them back to the cmbSDPFLine until they select something. I'll be doing this to 5 other textboxes also. I saw on a microsoft MSDN webpage that Case 1 is equal to vbOkonly. thank you.
 
Last edited:

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Change this:

Code:
cmbSDPFLine.SetFocus

to:

Code:
Cancel = True

And you really don't need all the Case selection etc. You can just do this:

Code:
If cmbSDPFLine.Value = "" Then
      MsgBox("Please select a production line.", vbOKOnly + vbExclamation & "Please Select Production Line")
    Cancel = True
End If

There answer is always going to be OK because that's the only choice they have.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,897
Messages
6,175,269
Members
452,628
Latest member
dd2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top