Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / September 2007

Tip: Looking for answers? Try searching our database.

Add UserForm to Control ‘Go to R    ecord’ on Mail Merge Toolbar

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
ryguy7272 - 27 Aug 2007 16:38 GMT
I’m starting a new post; I think my previous post was going off on a tangent
that was not really where I wanted to go.

Below is the code that was generated by recording a macro in word, while
searching for a specific Excel file (Contacts.xls), to do a basic Mail Merge.


Sub Macro2()

   ActiveDocument.MailMerge.MainDocumentType = wdFormLetters
   ActiveDocument.MailMerge.OpenDataSource Name:= _
       "J:\Contacts.xls", ConfirmConversions:=False, ReadOnly _
       :=False, LinkToSource:=True, AddToRecentFiles:=False,
PasswordDocument:= _
       "", PasswordTemplate:="", WritePasswordDocument:="", _
       WritePasswordTemplate:="", Revert:=False, Format:=wdOpenFormatAuto, _
       Connection:= _
       "Provider=Microsoft.Jet.OLEDB.4.0;Password="""";User ID=Admin;Data
Source=J:\Contacts.xls;Mode=Read;Extended Properties=""HDR=YES;IMEX=1;"";Jet
OLEDB:System database="""";Jet OLEDB:Registry Path="""";Jet OLEDB:Database
Password="""";Jet OLEDB:Engin" _
       , SQLStatement:="SELECT * FROM `Contacts`", SQLStatement1:="",
SubType:= _
       wdMergeSubTypeAccess
   ActiveDocument.MailMerge.ViewMailMergeFieldCodes = wdToggle
End Sub

This works fine.  I am now wondering if I can customize it a little by
adding a feature that prompts the user for an input, perhaps through a
UserForm, to find the client address that will be included on a specific form
letter.  We have all clients listed in the Excel file and each is identified
by ID number.  I can control which address is input through the Mail Merge
toolbar, by using the ‘Go to Record’.  I just want to personalize it a little
more by adding a UserForm that pops up, prompts the user for a number, and
this loads into the ‘Go to Record’.

Can this be done?

Regards,
Ryan---

Signature

RyGuy

Doug Robbins - Word MVP - 27 Aug 2007 20:48 GMT
See the article "Load a ListBox from a Named Range in Excel using DAO" at:

http://www.word.mvps.org/FAQs/InterDev/FillListBoxFromXLDAO.htm

Signature

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

> I'm starting a new post; I think my previous post was going off on a
> tangent
[quoted text clipped - 42 lines]
> Regards,
> Ryan---
Russ - 28 Aug 2007 07:29 GMT
If you are going to query for one number than what I advised you before
would be sufficient. Use an InputBox.
"Use an inputbox(See Word VBA Help) to get the number from the user."

> I¹m starting a new post; I think my previous post was going off on a tangent
> that was not really where I wanted to go.
[quoted text clipped - 36 lines]
> Regards,
> Ryan---

Signature

Russ

drsmN0SPAMikleAThotmailD0Tcom.INVALID

RyGuy - 29 Aug 2007 16:04 GMT
Doug, thanks for the link!!  This is an awesome idea!  I got the data to load
into the ListBox, and I added a CommandButton, but I can’t seem to get the
items selected in the ListBox to load into the word document.  

I added the following line of text:  
AddressBlock = db

This causes a Run-Time error '3420' and the message says, 'Object invalid or
no longer set.'  I got AddressBlock from insert > Field > AddressBlock, and I
though this was required to identify the place that the address will be
linked to.  Any ideas about what may be missing?  I’d like to get this
working soon.

Russ, I like your idea very much!  I’m going to have to research this
further.  Do you know of any links that may be helpful for getting this set
up and working?

Thanks again guys!
Ryan--

> If you are going to query for one number than what I advised you before
> would be sufficient. Use an InputBox.
[quoted text clipped - 40 lines]
> > Regards,
> > Ryan---
Doug Robbins - Word MVP - 30 Aug 2007 10:03 GMT
You use the .BoundColumn attribute of the list box to get hold of the data
from each column of the selected record.

The following bit of code constructs an "address block" and inserts it into
the range of a bookmark in the document,

Private Sub CommandButton1_Click()
Dim i As Integer, Addressee As String
Addressee = ""
For i = 1 To ListBox1.ColumnCount
   ListBox1.BoundColumn = i
   Addressee = Addressee & ListBox1.Value & vbCr
Next i
ActiveDocument.Bookmarks("Addressee").Range.InsertAfter Addressee
UserForm1.Hide
End Sub

If you want to scatter the information throughout the document, I would
write the information from each column to a document variable and use
{DOCVARIABLE } fields in the document to display the information

With ActiveDocument
   Listbox1.BoundColumn=1
   .Variables("varname1").Value = Listbox1
   ListBox1.BoundColumn=2
   .Variables("varname2").value = Listbox2
   'etc
   .Range.Fields.Update
End With

Signature

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

> Doug, thanks for the link!!  This is an awesome idea!  I got the data to
> load
[quoted text clipped - 75 lines]
>> > Regards,
>> > Ryan---
ryguy7272 - 31 Aug 2007 14:46 GMT
Unreal!!!!!!!  This code does exactly what I want.  I will have to modify my
source data a bit, but I’m very close to being done with this project now.  
Thanks Doug!!  Please tell me where I can learn more about this stuff.  I
know Excel pretty well, but I don’t know much about integrating Excel with
Word (and vice versa).  Where did you learn about this code?  I would really
appreciate it if you can recommend a good book, or a few good URLs (besides
the one you gave me already).  Hope you have a great Labor Day Weekend (I
know I will because this project is almost done now).

Kind regards,
Ryan---

> You use the .BoundColumn attribute of the list box to get hold of the data
> from each column of the selected record.
[quoted text clipped - 105 lines]
> >> > Regards,
> >> > Ryan---
Doug Robbins - Word MVP - 31 Aug 2007 21:38 GMT
To expand your knowledge, browse around the other pages at the Word MVP site
to which I refered you earlier.  The only other reference sources that I
have are the VBA help file and using the Advanced Groups Search at Google
Groups

http://groups.google.com/groups/dir?sel=33606782&expand=1

Signature

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

> Unreal!!!!!!!  This code does exactly what I want.  I will have to modify
> my
[quoted text clipped - 132 lines]
>> >> > Regards,
>> >> > Ryan---
ryguy7272 - 01 Sep 2007 19:48 GMT
I bookmarked it!  
Thanks again!!
Ryan--
Signature

RyGuy

> To expand your knowledge, browse around the other pages at the Word MVP site
> to which I refered you earlier.  The only other reference sources that I
[quoted text clipped - 139 lines]
> >> >> > Regards,
> >> >> > Ryan---
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.