User Form

T

Tripla

I have created a user form for a letter template and would like the
senders information to stay the same if saved (kind of like
personalizing the template), unless cleared. My problem is coding the
form to keep the senders information intact upon opening. I have this
as my code wondering if I should go about this differently:
Public Sub cmdClose_Click()
Application.ScreenUpdating = False
With ActiveDocument
.Bookmarks("To").Range.Text = txtTo.Value
.Bookmarks("Attn").Range.Text = txtAttn.Value
.Bookmarks("Faxto").Range.Text = txtFaxto.Value
.Bookmarks("Phoneto").Range.Text = txtPhoneto.Value
.Bookmarks("From").Range.Text = txtFrom.Value
.Bookmarks("Faxfrom").Range.Text = txtFaxfrom.Value
.Bookmarks("Phonefrom").Range.Text = txtPhonefrom.Value
.Bookmarks("Date").Range.Text = txtDate.Value
.Bookmarks("Notes").Range.Text = txtNotes.Value
.Bookmarks("Pages").Range.Text = txtPages.Value
End With
Application.ScreenUpdating = True
Unload Me
End Sub

Any help is appreciated
Thanks
Tripla
 
J

Jonathan West

Tripla said:
I have created a user form for a letter template and would like the
senders information to stay the same if saved (kind of like
personalizing the template), unless cleared. My problem is coding the
form to keep the senders information intact upon opening. I have this
as my code wondering if I should go about this differently:
Public Sub cmdClose_Click()
Application.ScreenUpdating = False
With ActiveDocument
.Bookmarks("To").Range.Text = txtTo.Value
.Bookmarks("Attn").Range.Text = txtAttn.Value
.Bookmarks("Faxto").Range.Text = txtFaxto.Value
.Bookmarks("Phoneto").Range.Text = txtPhoneto.Value
.Bookmarks("From").Range.Text = txtFrom.Value
.Bookmarks("Faxfrom").Range.Text = txtFaxfrom.Value
.Bookmarks("Phonefrom").Range.Text = txtPhonefrom.Value
.Bookmarks("Date").Range.Text = txtDate.Value
.Bookmarks("Notes").Range.Text = txtNotes.Value
.Bookmarks("Pages").Range.Text = txtPages.Value
End With
Application.ScreenUpdating = True
Unload Me
End Sub

Hi Tripla

When opening the form, you want to do the reverse assignment

With ActiveDocument
txtTo.Value =.Bookmarks("To").Range.Text

etc.

This populates the userform with the current contents of the bookmarks. Put
this code into the UserForm_Initialize event.

--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
R

Rob

In this office we have a lot of forms that do something similar except the
data is never stored in the templates because new docs are always created
from them. I have to save user data like their fax and extension, etc, to
populate forms for them. To do this I use System.PrivateProfileString in the
initialize to store and get stuff from their registry. Just thought I'd
mention that as an option.
 
D

Doug Robbins - Word MVP

In the Initialize event of your userform, include the command

txtFrom.Text = Application.UserName

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

Top