[mso] Re: word mail merge no longer working from access
- From: bccamper@xxxxxxxxxx
- To: mso@xxxxxxxxxxxxx
- Date: Fri, 23 Sep 2005 12:58:07 -0700
Hi Cathy,
Thanks again for your help.
I followed an example in this URL you send me
(http://www.windowsdevcenter.com/pub/a/windows/excerpt/acsckbk/?page=2).
From that example here is my code.
Public Const conTemplate As String = "Letters-Vendors.dot"
Public Const conQuery As String = "Letters-Vendor"
Public Sub MailMerge()
Dim strPath As String
Dim strDataSource As String
Dim doc As Word.Document
Dim wrdApp As Word.Application
On Error GoTo HandleErrors
' Delete the rtf file, if it already exists.
strPath = FixPath(CurrentProject.Path)
strDataSource = strPath & conQuery & ".doc"
Kill strDataSource
' Export the data to rtf format.
DoCmd.OutputTo acOutputQuery, conQuery, _
acFormatRTF, strDataSource, False
' Start Word using the mail merge template.
Set wrdApp = New Word.Application
Set doc = wrdApp.Documents.Add(strPath & conTemplate)
' Do the mail merge to a new document.
With doc.MailMerge
.OpenDataSource Name:=strDataSource
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
If .State = wdMainAndDataSource Then
.Execute
End If
End With
' Display the mail merge document.
wrdApp.Visible = True
ExitHere:
Set doc = Nothing
Set wrdApp = Nothing
Exit Sub
HandleErrors:
Select Case Err.Number
Case 53 ' File not found.
Resume Next
Case Else
MsgBox Err.Number & ": " & Err.Description
Resume ExitHere
End Select
End Sub
Private Function FixPath(strPath As String) As String
If Right(strPath, 1) = "\" Then
FixPath = strPath
Else
FixPath = strPath & "\"
End If
End Function
The example on the web page said to make the two Const's as Private, but i
could
not get my code to work until I made them public. As you can see I have my
constants pointing to one dot file and to one query. Because I have many mail
merges getting data from many queries I need this to be more dynamic. Other
wise
I will have to duplicate this code 100 or so times.
On 23 Sep 2005 at 8:10, Cathy.Evans@xxxxxxxxx wrote:
>
> Yes, you can do multiple letters, I have a sample to get to you but am not
> having much luck signing into the area where we can share files. Specific
> problem is though I've got my password, am not finding the 'group' to be
> able to join or don't know the smartgroups email when I try to login. I
> sure don't know what I'm doing!
>
> The deal about multiple letters is the data. Is the data the same that
> goes to the different letters? You may have to have forms that are grouped
> by data type. In other words, if you have 10 letters that need the same
> data, one form would have a pull down list of those ten forms, and so
> forth. If the data is different in each letter, would need to determine
> the basics, and build from there. Example, if name, address, phone are
> common to all letters, start with that on the form, then have it lead to
> other forms from a drop down or listbox, depending on the second dataset
> needed. The first dataset would transfer to second form and you'd build
> from there.
>
> The multiple forms part is handled by loading the form names in a table,
> and the code in the sample (reached with much help from others) opens those
> forms loaded in the table. The forms are all loaded into the same
> directory as database, and they open as a new file so your masters are
> protected.
>
> Not sure about your second question, as I'm not sure which sample or code
> you are running.
>
> Hope this helps, and will see how to get you the sample.
> Cathy
>
>
>
>
>
> bccamper@xxxxxxxxxx
>
> Sent by: To: mso@xxxxxxxxxxxxx
>
> mso-bounce@freelist
>
> s.org cc:
>
> 09/22/2005 06:04 PM
>
> Please respond to Subject: [mso] Re: word mail
> merge no longer working from access
> mso
>
>
> .....
>
>
>
>
>
>
> Hi Cathy,
>
> Thanks again for your help. Take your time and get back to me with any help
> whenever you have time. I actually made headway with the code from the
> first URL
> you gave me.
>
> I have a couple of questions about this though.
>
> Can the code be changed so I can use the code for multiple letters. I have
> about
> 140 docuuments that get merged from Access data and I don't want to code it
> for
> each document.
>
> Also when I try to run the MailMerge sub from VBA it works great. But when
> I
> specify the MailMerge Sub behind my command button, and then run it from
> the
> command button, it fails on a 2487 error - The Object Type argument for the
> action
> or method is blank or invalid. Is this have anything to do with the fact
> that the
> Const's are private?
>
>
>
>
>
>
>
> -----------------------------------------------------------------------------------------------------
> The information transmitted is intended only for the person
> or entity to which it is addressed and may contain proprietary,
> business-confidential and/or privileged material.
> If you are not the intended recipient of this message you
> are hereby notified that any use, review, retransmission,
> dissemination, distribution, reproduction or any action taken
> in reliance upon this message is prohibited. If you received
> this in error, please contact the sender and delete the
> material from any computer. Any views expressed in this message
> are those of the individual sender and may not necessarily reflect
> the views of the company.
> -------------------------------------------------------------------------------------------------------
>
> *************************************************************
> You are receiving this mail because you subscribed to mso@xxxxxxxxxxxxx or
> MicrosoftOffice@xxxxxxxxxxxxxxxx
>
> To send mail to the group, simply address it to mso@xxxxxxxxxxxxx
>
> To Unsubscribe from this group, send an email to
> mso-request@xxxxxxxxxxxxx with the word "unsubscribe" (without the quotes) in
> the subject line.
>
> Or, visit the group's homepage and use the dropdown menu. This will also
> allow you to change your email settings to digest or vacation (no mail).
> http://www.freelists.org/webpage/mso
>
> To be able to use the files section for sharing files with the group, send a
> request to mso-moderators@xxxxxxxxxxxxx and you will be sent an invitation
> with instructions. Once you are a member of the files group, you can go here
> to upload/download files:
> http://www.smartgroups.com/vault/msofiles
> *************************************************************
*************************************************************
You are receiving this mail because you subscribed to mso@xxxxxxxxxxxxx or
MicrosoftOffice@xxxxxxxxxxxxxxxx
To send mail to the group, simply address it to mso@xxxxxxxxxxxxx
To Unsubscribe from this group, send an email to
mso-request@xxxxxxxxxxxxx with the word "unsubscribe" (without the quotes) in
the subject line.
Or, visit the group's homepage and use the dropdown menu. This will also allow
you to change your email settings to digest or vacation (no mail).
http://www.freelists.org/webpage/mso
To be able to use the files section for sharing files with the group, send a
request to mso-moderators@xxxxxxxxxxxxx and you will be sent an invitation with
instructions. Once you are a member of the files group, you can go here to
upload/download files:
http://www.smartgroups.com/vault/msofiles
*************************************************************
- References:
- [mso] Re: word mail merge no longer working from access
- From: Cathy . Evans
Other related posts:
- » [mso] word mail merge no longer working from access
- » [mso] Re: word mail merge no longer working from access
- » [mso] Re: word mail merge no longer working from access
- » [mso] Re: word mail merge no longer working from access
- » [mso] Re: word mail merge no longer working from access
- » [mso] Re: word mail merge no longer working from access
- » [mso] Re: word mail merge no longer working from access
- » [mso] Re: word mail merge no longer working from access
- [mso] Re: word mail merge no longer working from access
- From: Cathy . Evans