Path/File access error ~ creating forms at runtime

M

msdickey

Background: I am trying to create userforms at runtime. I am using the
following code to do so:

Do until frmcount > 5
Set newFrmTemp = ActiveDocument.VBProject.VBComponents.Add(vbext_ct_MSForm)

With newFrmTemp
.Properties("Name") = "frmTemplate" & frmcount
.Properties("Caption") = "Template" & frmcount
.Properties("Height") = 180
.Properties("Width") = 273
End With

frmcount = frmcount + 1
Loop

Question: This creates 5 new userforms. Let's say I run this macro and it
creates all the forms. If I go and delete all of those forms created at
runtime and then try to rerun the macro again I get a Path/File access error.
For some reason it can't recreate those forms with that same name. So, in
other words, everytime I want to rerun the macro I have to close the file and
reopen it to clear those form names.

Why am I having to do that? If I create forms at design and then delete them
I don't have trouble creating a new form with that same name again. What am I
doing wrong? How can I fix it?
 
W

Word Heretic

G'day "msdickey" <[email protected]>,

Try unloading the forms instead if setting them to nothing - does that
help? This might be the difference I've been looking for :)

Steve Hudson - Word Heretic

steve from wordheretic.com (Email replies require payment)
Without prejudice


msdickey reckoned:
 

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