Template with User Form Required Fields

A

aehan

Hello all

I have created a template which uses a user form to populate sender and
recipient information on a template.

I'm pleased with the result, except for one thing. I cannot work out how to
keep the user form active if any of the required fields are not filled in.
What I would like to do is when the OK button is pressed and any of the
required fields are empty, then a message is sent to the user and the form
stays on screen. I have added this piece of code as part of the
OKbutton_click sub routine:

If Len(Trim(ComboBox1.text)) <= 0 Or Len(Trim(ComboBox2.text)) <= 0 Or
Len(Trim(DeptAddress.text)) <= 0 _
Or Len(Trim(EMail.text)) <= 0 Or Len(Trim(Addressee.text)) <= 0 Or
Len(Trim(Address.text)) <= 0 _
Or Len(Trim(Sal.text)) <= 0 Then
MsgBox "You must fill in all the required fields"
UserForm1.Enabled = True

End If

The message comes up, however the form closes and the letter opens up. So
miserable failure. Can anyone help me please?

Thank you
Aehan
 
D

Doug Robbins - Word MVP

Add an Exit Sub after the MsgBox command.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
A

aehan

Doh! Thank you so much.

Aehan

Doug Robbins - Word MVP said:
Add an Exit Sub after the MsgBox command.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 

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