Userform field required

johnpants

New Member
Joined
Oct 31, 2005
Messages
44
Hi, I have a userform that people enter sales information into. What I am trying to do is that if they select 'Invoiced' from ComboBox6 then they must enter an invioce number in TextBox 10 before they are able to close the userform.

How easy is this to do? Could anyone tell me the code required?

Thanks,
John.
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.

Smitty

Legend
Joined
May 15, 2003
Messages
29,536
You could use something like this in your unload event:

<font face=tahoma><SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> CommandButton1_Click()
    <SPAN style="color:#007F00">'   Close Form</SPAN>
    <SPAN style="color:#00007F">If</SPAN> ComboBox6.Text = "Invoices" And TextBox10.Text = "" <SPAN style="color:#00007F">Then</SPAN>
        TextBox10.SetFocus
        MsgBox "You must enter an Invoice #!"
    Else: Unload Me
    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN>
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>

And/or something in the ComboBox exit event:

<font face=tahoma><SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> ComboBox6_Exit(<SPAN style="color:#00007F">ByVal</SPAN> Cancel <SPAN style="color:#00007F">As</SPAN> MSForms.ReturnBoolean)
    <SPAN style="color:#00007F">If</SPAN> ComboBox6.Text = "Invoices" <SPAN style="color:#00007F">Then</SPAN>
        TextBox10.SetFocus
        MsgBox "You must enter an Invoice #!"
    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN>
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>

Hope that helps,

Smitty
 

johnpants

New Member
Joined
Oct 31, 2005
Messages
44
thank you, the top one is just what I was looking for.

Appreciate the help.

John.
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,003
Messages
5,834,828
Members
430,324
Latest member
bosphoruskid

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
Top