UserForms

R

Roderick O'Regan

I've created a form with just one field that a user needs to complete. When
the commandbutton OK is selected it places the text written in the field
into a document.

However, I want the userform not to unload but to display again if the user
does not enter anything - merely presses the OK button.

Here is what I've written:
MainTitle = txtMainTitle

If MainTitle = "" Then
frmMainHeading.Hide
Unload frmMainHeading
'Reload it
frmMainHeading.Show
Load frmMainHeading
ElseIf MainTitle <> "" Then
frmMainHeading.Hide
Unload frmMainHeading
End If

This, of course appears to be wrong as it seems to go into some sort of
loop.

Any ideas, please, on how this could be made to work correctly?

Thanks

Roderick O'Regan
 
D

Doug Robbins - Word MVP

Hi Rod,

Use

If txtMainTitle <> "" Then
'insert main title into document
frmMainHeading.Hide
Else
Exit Sub
End If


--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 
R

Roderick O'Regan

Thanks Doug. That does it!

I also found, prior to an answer coming back via this newsgroup that there
is a group which seems to be dedicated to userforms.
(microsoft.public.word.vba.userforms). I'll know for next time!

Rod
 
J

J.Verdaasdonk

Hi Roderick,

Sounds to me that you want to make sure a user will fill
in you're form correctly?

If so you need to inform you're user he's doing something
wrong.

This is one way:
Private Sub cmdOk_Click()
If txtMainTitle.Value = vbNullString Then
MsgBox "Please fill in the Title value?",
vbInformation, "Information"
txtMainTitle.SetFocus
Else
'Do you're stuf

Unload Me
End If
End Sub

First the code check's for a NullString (in You're
code "")
If Found the user gets prompt of a MsgBox with the the
txt above!
After that the Focus (cursor) is set to the txtbox you
want filled in!

If the txtbox is Not a NullString then you're writing
code executes and the form is Unloaded by Unload Me(the
object that has the focus (UserForm))

Enjoy,
J.Verdaasdonk
 

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