Show Msgbox / stop code running if Combobox is empty

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,226
Office Version
  1. 2007
Platform
  1. Windows
Hi,
I am currently using the code below & also supplied a screenshot of the form.

The issue i have is that when i press CHECK MY PART NUMBER it should not continue to run the codeif ComboBox2 is empty.
Basically ComboBox2 should show a value for it to continue,if empty then i will add a Msgbox but not sure where ive gone wrong.

Please advise thanks



Rich (BB code):
Private Sub CheckMyPartNumber_Click()
    If ComboBox2.Value > 1 Then
        HondaParts.MyPartNumber.Value = ComboBox2.Value
        HondaParts.Show
    Else
        MsgBox "NO HONDA PART NUMBER WAS SELECTED", vbCritical, "HONDA PART NUMBER LOOK UP MESSAGE"
    End If

End Sub
 

Attachments

  • 1582.jpg
    1582.jpg
    82.3 KB · Views: 6

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Add
VBA Code:
exit sub
between msgbox and End If statements. this will end your procedure.
 
Upvote 0
Hi,
You mean like this ??
As if so its the same.

Rich (BB code):
    Else
        MsgBox "NO HONDA PART NUMBER WAS SELECTED", vbCritical, "HONDA PART NUMBER LOOK UP MESSAGE"
    Exit Sub
    End If

End Sub
 
Upvote 0
yuppers...

Assuming you have another piece of code running, after your End if statement, placing Exit Sub in between will simply end the sub, without proceeding once the msgbox is displayed.
 
Upvote 0
That didnt works and the code still runs.
The Msg in the code didnt even show
 
Upvote 0
this should have exited the code once your condition for partsnumber is matched and the msgbox is displayed.
 
Upvote 0
Wait
The question was if the value = 0 / empty value dont continue
 
Upvote 0
Its a list from a table BUT if i dont select anything and press CHECK MY PART NUMBER then the code should see that nothing was selected and then show the Msg in the code MsgBox "NO HONDA PART NUMBER WAS SELECTED", vbCritical, "HONDA PART NUMBER LOOK UP MESSAGE"

This part isnt happening
 
Upvote 0
Ok i think i got it.
The code should be

Rich (BB code):
If ComboBox2.ListIndex > -1 Then
 
Upvote 0

Forum statistics

Threads
1,214,594
Messages
6,120,436
Members
448,964
Latest member
Danni317

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