PDA

View Full Version : Solved: Multiple instances with AutoNew and Userform issue



BonnyeLiz
05-04-2005, 07:44 AM
If a Userform is run in coordination with an AutoNew macro containing other code, why would it intercept the initial document created AGAIN if a user tried to run the template for another separate new document? Wow - let me clarify that inquiry further...

I open a template that has an autonew macro creating a new doc based on the template and also includes code that gives it a filenumber, path and filename. This template also pops a userform up for data placement into the new doc created.

Now, why (when I have gone through the userform, clicked "OK" and everything places in the document accordingly) does the new instance of the userform and template populate the first document instead of a new one? The file number, path, etc. are all populated again into the initial doc created, and the secondary document I'm trying to create now has no filename, numbers assigned to it.

I'm thinking it could have something to do with the WITH statement in the code referencing ActiveDocument? But that doesn't quite make sense to me either considering that the new instance should now be the active document.

Hmmm.... not sure if anyone will be able to understand what I'm trying to explain here, but I tried! LOL :bug:

Killian
05-04-2005, 08:50 AM
I think your instincts are right and you're refering to the wrong document.
It might be worth posting the code that does that bit but as a rule, when you create a new doc from a template, you should set a reference to it so you can get hold of it easilySub test()

Dim MyNewDoc As Document

Set MyNewDoc = Documents.Add("templatename")

With MyNewDoc
'do stuff
End With

End Sub

MOS MASTER
05-04-2005, 02:07 PM
Hi Bonny, :D

Seams me Killian is Bang on with his assement! (But like he says we need to see the code that create the document as well as the code that writes (Userform) to the document)

The part in the Userform can also be the problem if perhaps you are using the "ThisDocument" property instead of the "ActiveDocument" property. (The method by Killian is even better because it holds the reference to the required document)

Enjoy! :whistle:

BonnyeLiz
05-05-2005, 11:59 AM
Whip Me, Beat Me :whip and knockme upside the head! :doh:

One simple little line was missing: Unload Me

Thanks for the help, guys - I'm going back to hide in the shadows of my embarrassment.
Bonnye

MOS MASTER
05-05-2005, 12:03 PM
Hi Bonny, :D

No problemo...but as you requested...:whip

Does seam strange the Unload Me statement is the problem over here..but haven't seen your code so if you say it does than it must be...

Till we meet again! :thumb