![]() |
|
![]() |
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
![]()
If a checkbox on Template1 is checked, then it will open another template by using Applications.documents.add ("c:\template2.dotm")
When template2 opens, I want the textboxes on the userform in template2 to populate with the information from the textboxes on the userform in template1. Basically, both templates use several of the same document variables and I want to pull the inputs from template1 to populate the userform in template2. Is this possible and, if so, how do I go about doing it? Thanks for any help! -- Mike |
#2
|
||||
|
||||
![]()
Are you expecting to have both userforms open at the same time? If so, you will need to make them modal.
If the userform reads document variables in order to populate the relevant userform on initialisation then you can simply read the document variables from one file and write them to the other file. For example Code:
Private Sub VariableTransmission() Dim doc1 As Document, doc2 As Document, aVar As Word.Variable Set doc1 = ActiveDocument Set doc2 = Documents.Add doc1.Variables.Add "First", "Hi mum" doc1.Variables.Add "Second", "Hello world" For Each aVar In doc1.Variables doc2.Variables.Add Name:=aVar.Name, Value:=aVar.Value Next aVar Debug.Print doc2.Variables("Second").Value End Sub
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#3
|
|||
|
|||
![]()
Thanks Andrew--I am off work until Monday, so I'll try then!
|
#4
|
|||
|
|||
![]()
Huh, that isn't working Andrew because it keeps saying the variable already exists in the second document
|
#5
|
||||
|
||||
![]()
This version doesn't error if the variable already exists and if the variable doesn't exist it creates it.
Code:
Private Sub VariableTransmission() Dim doc1 As Document, doc2 As Document, aVar As Word.Variable Set doc1 = ActiveDocument Set doc2 = Documents.Add doc1.Variables("First").Value = "Hi mum" 'resets value or creates if it doesn't already exist doc1.Variables("Second") = "Hello world" doc1.Variables("Second") = "Hello world" For Each aVar In doc1.Variables doc2.Variables(aVar.Name) = aVar.Value Next aVar Debug.Print doc2.Variables("Second").Value End Sub
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#6
|
|||
|
|||
![]()
ok, i have gotten it so that the information i enter on the userform in document 1 will show up as documentvariables in document 2, but it will not show up on the userform for document 2. Any thoughts? This is the code I am using right now in document1
If chxIFPOrder = True Then Set doc1 = ActiveDocument Set doc2 = Application.Documents.Add("C:\XXXX.dotm") doc2.Variables("myinitials").Value = Me.TxtYourInitials.Value End If When I do that, there is no myinitials information showing up on the userform itself in doc2, but when I hit OK on the userform in doc2, then the myinitials documentvariable populates with the myinitials information that I entered on the userform in doc1 shows up. I want the info to show up on the userform in doc2 also. Any help would be greatly appreciated! -- Mike |
#7
|
||||
|
||||
![]()
I can't see the code you have executing but the question is WHEN does the userform associated with doc2 initialised? If it initialises and populates the userform prior to the next line of code running then I would expect the userform for doc2 to show the initial value rather than the updated line
Set doc2 = Application.Documents.Add("C:\XXXX.dotm") 'does the userform load here or does it wait for the next line before loading it? doc2.Variables("myinitials").Value = Me.TxtYourInitials.Value
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#8
|
||||
|
||||
![]()
I am curious why you need two userforms for this when you appear to have both documents open. Wouldn't it make sense to provide the data to both documents from the same userform? In fact your code already appears to do that.
You could also read and write data via the registry using SaveSetting and GetSetting e.g. Code:
Public Function appID() As String appID = "MyApp" lbl_Exit: Exit Function End Function Code:
'Write SaveSetting appID, "Config", "My Initials", txtInitials.Text 'Read txtInitials.Text = GetSetting(appID, "Config", "My Initials", "Mr Dr")
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
![]() |
Thread Tools | |
Display Modes | |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
UserForm with Combo Box from data in table within template | jhansrod | Word VBA | 6 | 06-13-2019 09:02 AM |
Excel Userform to Word Template Bookmarks | JCrinage | Excel Programming | 1 | 11-02-2016 07:03 PM |
![]() |
kennyD | Word | 4 | 04-07-2015 01:32 PM |
userform to enter multiple lines of data in template | callasabra | Word VBA | 0 | 06-27-2014 05:29 PM |
How to get Outlook 2007 userform into template? | Royzer | Outlook | 0 | 04-13-2012 10:41 AM |