Forcing an input in a pop up box

D

David

Hi,

I have a user form that pops up when you open the
workbook with three text box inputs and one comman button
("Enter") to populate the text to certain fields. Can
someone please tell me the coding to force the user to
put a yes or no in each textbox before they can exit the
user form in order to advance to the worksheet? If they
try to go on w/out putting the right inputs, I would like
to dispaly a message, like "please provide an answer
first."

Also can you change the name of the userform so that it
doesn't say UserForm1 in the blue box when it pops up in
excel?

Any help is greatly apprecaited. My code is below:

Private Sub CommandButton1_Click()
Worksheets("Allocation").Range("M9").Value = TextBox1.Text
Worksheets("Allocation").Range("M11").Value =
TextBox2.Text
Worksheets("Allocation").Range("M42").Value =
TextBox3.Text
Worksheets("Allocation").Calculate
Unload Me

End Sub
 
J

Jim Thomlinson

Lets start with the easy one. Renameing the form.

In the VBA window bring up the properties window. (F4 key if is is not
already visible). When the form is selected you will see (Name) UserForm1.
This should be changed to something like "frmMain". To change the caption at
the top of the form select the Caption entry and change it to whatever floats
your boat...

Now for the validation

I assume you have textBox1, 2 and 3

Private Sub CommandButton1_Click()
dim blnAllOk as boolean

blnAllOk = true

if textbox1.text = "" then
textbox1.setfocus
blnallok = false
elseif textbox2.text = "" then
textbox2.setfocus
blnallok = false
elseif textbox3.text = "" then
textbox2.setfocus
blnallok = false
end if

if blnAllOk = true then
frmmain.unload
else
msgbox "Please ensure that all entries are completed before proceeding",
vbinformation, 'Input Error"

end sub

Hope this helps...
 
J

Jim Thomlinson

Oops shoud be...

msgbox "Please ensure that all entries are completed before proceeding",
vbinformation, "Input Error"
end if

Sorry... Darn these fingers...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top