UserForm problem

J

Jen

I'm trying to create a user form to automatically fill in repeated
information in a document based on a template. I've read the online
instructions at http://word.mvps.org/FAQs/Userforms/CreateAUserForm.htm and
http://gregmaxey.mvps.org/Repeating_Data.htm, but I'm running into a problem.

The instructions on the first link (#10) say to insert UserForm1.Hide in the
code. However, this seems to crash Word - I get an error message saying "Run
time error 402: must close or hide topmost modal form first".

I'm using Word 2003 SP2...is there some different code I need to use here?
Or did I just do something wrong? (Very likely!). I have quite a bit of
basic coding experience in Access but haven't ever done programming in Word.

Thanks,
Jen
 
D

Doug Robbins - Word MVP

Paste all of the code that you have into a message that you post back here
so that we can see what is going on.

--
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
 
J

Jen

There's not much code:

______________________
Sub autonew()

Dim myForm As UserForm1
Set myForm = New UserForm1
myForm.Show
Unload myForm
Set myForm = Nothing

End Sub
______________________
And, the code attached to the command button on UserForm1:

Private Sub CommandButton1_Click()

With ActiveDocument
.Bookmarks("CMOName").Range.InsertBefore CMOName
End With

UserForm1.Hide

End Sub
________________________

In my document, I've inserted a Bookmark called CMOName. Then, everywhere
else that text needs to show up, I've inserted a cross-reference to the
bookmark.

When I open the document and confirm "Enable Macros", the UserForm comes up
and I enter the data. When I click the command button, I get the error.
However, if I click "End" and look at the document, it has inserted the data
into the bookmarked location, but not the cross-referenced locations.

I hope this makes sense...thanks for any help you can provide.
 
D

Doug Robbins - Word MVP

The form that you have displayed is myForm. Hence it is that which you have
to hide either by using

myForm.Hide

or just

Me.Hide

--
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
 
J

Jen

Of course it is...doh!! I hate it when I read something over 100 times and
still miss something so painfully obvious.

Thanks.
 
D

Doug Robbins - Word MVP

Don't we all.

--
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

Similar Threads

UserForm 4
Userform and Bookmarks 6
UserForms +Error 4
cannot hide userform 4
Userform 4
Automating Templates - Continued 10
Hidden Spell checking dialog behind the userform 5
Blank Userform 1

Top