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.
 

Some videos you may like

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.

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.
 

Watch MrExcel Video

Forum statistics

Threads
1,118,455
Messages
5,572,235
Members
412,449
Latest member
mdvouf
Top