I have created a 2003 Word Template [2007 Compatibility Mode] that uses 2
userforms. (The 2 userforms are identical, except for the Name and some of
the VBA coding.)

The first userform loads when the template opens as a document to which the
user enters information in each field and upon clicking OK, the new document
populates with the entered information.

The second userform was created to appear with the help of a keyboard
shortcut macro to appear so that the user has the option of changing the
previously entered information.

My problem is that I want the second userform to populate with the
information that was previously entered. Here is a sampling of my code for
the second userform:

Private Sub DisplayEditForm1()
With ActiveDocument
txtProjectDescription =
ActiveDocument.Variables("ProjectDescription").Value
etcâ?¦..
End With
End Sub

I have tried some of the other posted suggestions, but I'm still having
problems.

Does anyone have any suggestions?

Thanks bunches!!

Re: Repopulate UserForm from Document by Jay

Jay
Fri Jul 11 19:40:45 PDT 2008

I'll assume that the first userform puts values into document variables, and
that the document displays those values in DocVariable fields, so the named
variables actually have values when the second userform launches.

The code for launching the second userform should look something like this:

Private Sub DisplayEditForm1()
Dim dlg As UserForm2 ' or whatever you named the second userform
Set dlg = New UserForm2

With ActiveDocument
dlg.txtProjectDescription = .Variables("ProjectDescription").Value
' etc.
End With

dlg.Show

Set dlg = Nothing
End Sub

Notice that txtProjectDescription is a text field in the userform, so it's a
member of dlg, indicated be the "dlg." in front of it. Do the same with the
other text fields in the userform.

Similarly, the .Variables collection is a member of the ActiveDocument object;
in this case, the ActiveDocument in front of .Variables is implied by the With
statement.

The dlg.Show is what makes the userform appear on screen. When the userform
hides itself (using Me.Hide in the code of the OK button), execution returns to
the next line in the macro, setting the dlg object to Nothing which frees the
userform's memory.

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so all
may benefit.

On Fri, 11 Jul 2008 15:31:00 -0700, Barb <Barb@discussions.microsoft.com> wrote:

>I have created a 2003 Word Template [2007 Compatibility Mode] that uses 2
>userforms. (The 2 userforms are identical, except for the Name and some of
>the VBA coding.)
>
>The first userform loads when the template opens as a document to which the
>user enters information in each field and upon clicking OK, the new document
>populates with the entered information.
>
>The second userform was created to appear with the help of a keyboard
>shortcut macro to appear so that the user has the option of changing the
>previously entered information.
>
>My problem is that I want the second userform to populate with the
>information that was previously entered. Here is a sampling of my code for
>the second userform:
>
>Private Sub DisplayEditForm1()
> With ActiveDocument
> txtProjectDescription =
>ActiveDocument.Variables("ProjectDescription").Value
> etc?..
> End With
>End Sub
>
>I have tried some of the other posted suggestions, but I'm still having
>problems.
>
>Does anyone have any suggestions?
>
>Thanks bunches!!

RE: Repopulate UserForm from Document by gordon(dot)bentleymix(at)gmail(dot)com>

gordon(dot)bentleymix(at)gmail(dot)com>
Sun Jul 13 16:14:02 PDT 2008

Barb,

Jay's post gives a very good explanation of how to achieve your desired
outcome. You may also find the information in my posts under the thread "Save
userform data" helpful.

However, I question the need to have a second UserForm that is identical to
the first with only some variation in the code (and the name - which becomes
a moot point). I frequently provide this sort of "rerun" functionality using
only one UserForm. I do this by using a document variable to track whether
I'm creating a new document or rerunning an existing one. The code I posted
in the thread referenced above shows how to do this.
--
Cheers!
Gordon

Uninvited email contact will be marked as SPAM and ignored. Please post all
follow-ups to the newsgroup.


"Barb" wrote:

> I have created a 2003 Word Template [2007 Compatibility Mode] that uses 2
> userforms. (The 2 userforms are identical, except for the Name and some of
> the VBA coding.)
>
> The first userform loads when the template opens as a document to which the
> user enters information in each field and upon clicking OK, the new document
> populates with the entered information.
>
> The second userform was created to appear with the help of a keyboard
> shortcut macro to appear so that the user has the option of changing the
> previously entered information.
>
> My problem is that I want the second userform to populate with the
> information that was previously entered. Here is a sampling of my code for
> the second userform:
>
> Private Sub DisplayEditForm1()
> With ActiveDocument
> txtProjectDescription =
> ActiveDocument.Variables("ProjectDescription").Value
> etcâ?¦..
> End With
> End Sub
>
> I have tried some of the other posted suggestions, but I'm still having
> problems.
>
> Does anyone have any suggestions?
>
> Thanks bunches!!

RE: Repopulate UserForm from Document by Barb

Barb
Thu Jul 17 07:38:04 PDT 2008

Jay and Gordon, thanks so much for your input; youâ??re both amazing!

Since Iâ??m relatively a newbie at VBA and this is a lot of information for me
to digest, Iâ??m going to work with the coding you both suggested to see which
works best for my application.

Thanks again!!