Access 2003 Mail Merge to Word 2003 using query to locate the specific record being displayed

After spending ALL DAY searching the entire WEB I have found a lot of
posts asking this same question but not one answer.

I thought I's throw it up again.

The button on my form does this.  * From Mergit() *

   Dim objWord As Word.Document
   Set objWord = GetObject("H:\Contract Admin Database\Merge Documents
\WIP\Closings\Closing Packet Documents\Test - closing packet EM.doc",
"Word.Document")
   objWord.Application.Visible = True
   ' Set the mail merge data source as the Northwind database.
   objWord.MailMerge.OpenDataSource _
      Name:="H:\Contract Admin Database\Development\CA.mdb", _
      LinkToSource:=True, _
      Connection:="Query Q_CA_MergeDocsMaster", _
      SQLStatement:="SELECT * FROM [Q_CA_MergeDocsMaster] WHERE
((Q_CA_MergeDocsMaster.Job_Key)=[Forms]![WordMerge]![Job_Key])", _
      SubType:=wdMergeSubTypeWord2000
      objWord.MailMerge.Execute

The Word document opens and the merge even executes, but totally
ignoring the WHERE clause.
Can anyone tell me why the WHERE part is ignored by the merge?

0
ehorde
9/25/2007 11:41:57 PM
access 16762 articles. 3 followers. Follow

8 Replies
818 Views

Similar Articles

[PageSpeed] 23

Not done that myself but maybe
 Connection:="Query Q_CA_MergeDocsMaster"
overrides
    SQLStatement:="SELECT * FROM [Q_CA_MergeDocsMaster] WHERE 
((Q_CA_MergeDocsMaster.Job_Key)=[Forms]![WordMerge]![Job_Key])"

?
can't see the need for both

Pieter


<ehorde@hotmail.com> wrote in message 
news:1190763717.554303.295330@19g2000hsx.googlegroups.com...
> After spending ALL DAY searching the entire WEB I have found a lot of
> posts asking this same question but not one answer.
>
> I thought I's throw it up again.
>
> The button on my form does this.  * From Mergit() *
>
>   Dim objWord As Word.Document
>   Set objWord = GetObject("H:\Contract Admin Database\Merge Documents
> \WIP\Closings\Closing Packet Documents\Test - closing packet EM.doc",
> "Word.Document")
>   objWord.Application.Visible = True
>   ' Set the mail merge data source as the Northwind database.
>   objWord.MailMerge.OpenDataSource _
>      Name:="H:\Contract Admin Database\Development\CA.mdb", _
>      LinkToSource:=True, _
>      Connection:="Query Q_CA_MergeDocsMaster", _
>      SQLStatement:="SELECT * FROM [Q_CA_MergeDocsMaster] WHERE
> ((Q_CA_MergeDocsMaster.Job_Key)=[Forms]![WordMerge]![Job_Key])", _
>      SubType:=wdMergeSubTypeWord2000
>      objWord.MailMerge.Execute
>
> The Word document opens and the merge even executes, but totally
> ignoring the WHERE clause.
> Can anyone tell me why the WHERE part is ignored by the merge?
> 


0
Pieter
9/26/2007 12:05:21 AM
<ehorde@hotmail.com> wrote in message 
news:1190763717.554303.295330@19g2000hsx.googlegroups.com...


WHERE
> ((Q_CA_MergeDocsMaster.Job_Key)=[Forms]![WordMerge]![Job_Key])", _
>      SubType:=wdMergeSubTypeWord2000
>      objWord.MailMerge.Execute
>
> The Word document opens and the merge even executes, but totally
> ignoring the WHERE clause.
> Can anyone tell me why the WHERE part is ignored by the merge?


What happens if you need to search for a job key names [forms]![WordMerge]

How would you search for text called "[forms]", and not the value 
represented by the form?

Word does not know about forms, and forms expression in ms-access. You have 
to correct form the sql,a and sub-mit that sql to word.

In other words, build the correct sql *string* FIRST...

dim strSql       as string

strSql = "SELECT * FROM [Q_CA_MergeDocsMaster] WHERE " & _
         " Job_Key = " & [Forms]![WordMerge]![Job_Key]

furhter, if job key is a string value, the you need to add quotes:

strSql = "SELECT * FROM [Q_CA_MergeDocsMaster] WHERE " & _
         " Job_Key = '" & [Forms]![WordMerge]![Job_Key] & "'"

I *think* single quotes will work with word, but I not sure...

The next line of code you need (for testing) is:

debug.print strSql
msgbox strSql

Then, you can use your word informaton...

    SQLStatement:= strSql

The "display" of the sql and the debug.print can be removed when you get it 
working.

On the other hand, you opening up a can of words and allowing word to attach 
to the mdb file is a source of problems.

I would suggest you try my following sample code. To merge your current 
record, your code would be


MergeSingeword.

Yup...one line of code!!!


The sample I have can be found here:

http://www.members.shaw.ca/AlbertKallal/msaccess/msaccess.html

What is nice/interesting about my sample is that is specially designed to 
enable ANY form with ONE LINE of code....

Thus, each time you build a new form, you can word merge enable it with 
great ease, and not have to write a lot of new code...


-- 
Albert D. Kallal    (Access MVP)
Edmonton, Alberta Canada
pleaseNOOSpamKallal@msn.com
You can find my merge example here:



0
Albert
9/26/2007 12:08:20 AM
On Sep 25, 7:41 pm, eho...@hotmail.com wrote:
> After spending ALL DAY searching the entire WEB I have found a lot of
> posts asking this same question but not one answer.
>
> I thought I's throw it up again.
>
> The button on my form does this.  * From Mergit() *
>
>    Dim objWord As Word.Document
>    Set objWord = GetObject("H:\Contract Admin Database\Merge Documents
> \WIP\Closings\Closing Packet Documents\Test - closing packet EM.doc",
> "Word.Document")
>    objWord.Application.Visible = True
>    ' Set the mail merge data source as the Northwind database.
>    objWord.MailMerge.OpenDataSource _
>       Name:="H:\Contract Admin Database\Development\CA.mdb", _
>       LinkToSource:=True, _
>       Connection:="Query Q_CA_MergeDocsMaster", _
>       SQLStatement:="SELECT * FROM [Q_CA_MergeDocsMaster] WHERE
> ((Q_CA_MergeDocsMaster.Job_Key)=[Forms]![WordMerge]![Job_Key])", _
>       SubType:=wdMergeSubTypeWord2000
>       objWord.MailMerge.Execute
>
> The Word document opens and the merge even executes, but totally
> ignoring the WHERE clause.
> Can anyone tell me why the WHERE part is ignored by the merge?

Update, even though it opens the document Access eventually errors out
and says -  "Run Time Error '5922': Word was unable to open the data
source.

I think the merge data coming in is from the document's pre-defined
original datasource.

0
ehorde
9/26/2007 12:20:02 AM
<ehorde@hotmail.com> wrote in message 
news:1190766002.648107.308890@r29g2000hsg.googlegroups.com...


> I think the merge data coming in is from the document's pre-defined
> original datasource.
>

*excellent* obseation on your part.....

just run the word macro reocrder..and open up the mdb file...you see how it 
sets the data source...

eg:

I tried the word macro recorder, you get somting like:

      Format:=wdOpenFormatAuto, Connection:= _
      "Provider=Microsoft.Jet.OLEDB.4.0;Password="""";User ID=Admin;Data 
Source=C:\Documents and Settings\Albert\My 
Documents\db5_be.mdb;Mode=Read;Extended Properties="""";Jet OLEDB:System 
database="""";Jet OLEDB:Registry Path="""";Jet OLEDB:Database 
Password="""";Jet OLE" _
      , SQLStatement:="SELECT * FROM `Contacts`", SQLStatement1:="", 
SubType:= _

so, you have to add in the connection string to tell word the path name.

And, as mentioned, the word merge can't use open forms...it is not 
ms-access, and it is NOT aware of values and data in form. You have to pass 
word CORRECTLY formed sql, with no references, or expression to forms......

Or, you can use my sample code, and write ONE line of code....


-- 
Albert D. Kallal    (Access MVP)
Edmonton, Alberta Canada
pleaseNOOSpamKallal@msn.com


0
Albert
9/26/2007 12:43:56 AM
>>And, as mentioned, the word merge can't use open forms...it is not
>>ms-access, and it is NOT aware of values and data in form. You have to pass
>>word CORRECTLY formed sql, with no references, or expression to forms......

OK, let me get this straight "word merge can't use open forms"?
Is that true?
If so, it explains all the frustration I see posted from other people
trying to do this.

>>Or, you can use my sample code, and write ONE line of code....

I downloaded it, I will give it a try.

Thanks,

Eric

0
ehorde
9/26/2007 1:01:41 AM
<ehorde@hotmail.com> wrote in message 
news:1190768501.517060.152940@r29g2000hsg.googlegroups.com...
>>>And, as mentioned, the word merge can't use open forms...it is not
>>>ms-access, and it is NOT aware of values and data in form. You have to 
>>>pass
>>>word CORRECTLY formed sql, with no references, or expression to 
>>>forms......
>
> OK, let me get this straight "word merge can't use open forms"?
> Is that true?

Yes, word can't assume that you have ms-access installed. Further, a form is 
code designed by you the developer. Word can't launch that form and run it. 
That form might email home, empty your bank account out,  who knows, maybe 
that form is a video game.....

You have to supply valid sql to that word merge. It is word that running the 
sql here. It knows nothing about ms-access, or simply accounting, or 
whatever.....

Word cannot be expected to run, load, and know how to execute any piece of 
software on your computer.

However, YOUR CODE can simply pull the needed values form the form, and THEN 
supply the correct sql in code to word. (so, while a VERY minor difference 
in coding, it is a GRAND canyon of difference in what one is asking of 
word).

so,

strSql = "select * from table
          where company = forms!Cust!Company" <-- not good

strSql = "select * from table
      where company = '" & forms!Cust!Company & "'" <-- this ok


So, if you use code in ms-access to RESOLVE the 7 to a value, then your home 
free.

Try using a msgbox command to display the above two examples in ms-access,a 
and you INSTANT understand what is occurring here.

Anyway, my sample takes care of this stuff, don't forget the step by step 
instructions on how to use my sample in your existing application, they can 
be found here:

http://www.members.shaw.ca/AlbertKallal/wordmerge/page2.html

-- 
Albert D. Kallal    (Access MVP)
Edmonton, Alberta Canada
pleaseNOOSpamKallal@msn.com


0
Albert
9/26/2007 2:08:45 AM
Albert,

Your program looks really slick.  I think it will work nicely for us.
I am running into a problem though.

When I try to "Add New Template" I am getting:

      Run-Time error: '-2147417851 (80010105)':
      Method 'Add' of object 'Documents' failed

Clicking Debug highlights this code:

      Set WordDoc = wordApp.Documents.Add

I followed your instructions perfectly for the install.

0
ehorde
9/26/2007 1:48:58 PM
On Sep 26, 9:48 am, eho...@hotmail.com wrote:
> Albert,
>
> Your program looks really slick.  I think it will work nicely for us.
> I am running into a problem though.
>
> When I try to "Add New Template" I am getting:
>
>       Run-Time error: '-2147417851 (80010105)':
>       Method 'Add' of object 'Documents' failed
>
> Clicking Debug highlights this code:
>
>       Set WordDoc = wordApp.Documents.Add
>
> I followed your instructions perfectly for the install.

Got it working by adding this...

      MergeSingleWord "H:\Contract Admin Database\Merge Documents
\Documents", True

Albert, you should get some kind of award for this code.  Best stuff
I've seen yet.


0
ehorde
9/26/2007 3:14:06 PM
Reply:

Similar Artilces:

E-Mail Address with French Characters
I attempting to create an e-mail adrress with French=20 caharacters (Fran=E7oise), but it will not allow the =E7=20 character. I keep getting an Invalid Character error=20 message. How can I create this e-mail address? Thank you. Jim itest@colorlabcosmetics.com "Jim" <itest@colorlabcosmetics.com> wrote: >I attempting to create an e-mail adrress with French >caharacters (Fran�oise), but it will not allow the � >character. I keep getting an Invalid Character error >message. > >How can I create this e-mail address? I don't think that trying to use...

Outlook Web Access AutoSignature
I would like to know if it's possible to have autosignature in Outlook Web Access, and if so how to implement it. If anyone can help, it would be greatly apreciated. Thank You. It depends on the version of Exchange - Outlook Web Access is a function of Exchange, not Outlook. Exchange 2003 does this natively, previous versions may have a third party add-in that will allow users to do this. For better information, post in an exchange group such as microsoft.public.exchange.admin. --� Milly Staples [MVP - Outlook] Post all replies to the group to keep the discussion intact. Due t...

Restricting access to note attachments
Hi all, is there a way to restrict access to attachments on notes to specified users. I know we can, using the Security Roles, define who can and can't read/ write the notes fields but we would like our users to be able to view the note, but not open the attachment(s) unless they are the owner of that note (or at least in the business unit, etc.). I know this could be done for Word/ Excel files in Office (Password protection) but are looking for something more encompassing for all attachments inside CRM. Thanks, -- Matt Pring On Oct 21, 3:54=A0pm, Matt Pring <MattPr...@discus...

Menu Change back to 2003
Does anybody can tell me how to change the word word 2007 menu back to word 2003 menu?Word 2007 is a nightmare for me! Hi Bo, You can't. However, there are various Add-ins that people have produced to mimick the old toolbars. -- Cheers macropod [Microsoft MVP - Word] "Bo" <Bo@discussions.microsoft.com> wrote in message news:D2269CDD-43F0-4138-BB86-07E685A1AFA8@microsoft.com... > Does anybody can tell me how to change the word word 2007 menu back to word > 2003 menu?Word 2007 is a nightmare for me! As macropod suggests there are add-ins that mim...

Exchange 2003 Email forwarding by Schedule
Hi, I have been looking for some VB code example, without any luck, on forwarding Exchange 2003 email accounts to another email account within exchange using a script. I need to forward and unforward on a schedule. Can anyone direct me to some info that would help me acheive this. Regards Brent Might not be a good solution but: AD Attrib altRecipient is the forward to option. You can easily put a script in place that will modify this value to a single user and then schedule the script to change the forward to as required. Of course AD replication is required after the change and it ...

outlook 2003 custom rules and spam filtering
I'm trying to set up rules to move emails from different accounts to different folders. The rules work fine except that spam filtering is not being processed on the accounts that get moved. In other words, I have one "main" account that I have go to the inbox - it has the spam rules apply. The other "secondary" rules go to specific folders - they do not have the spam being processed. Sounds like my custom rule is pre-empting the spam filter rule(s). Is there a way to chain the two together so that spam filtering happens first and then the mover (or vice versa ...

Amount or Numbers in Words
I would like to know if there is any way that I can change numbers/amounts in words form using EXCEL. Eg: $1,498(sum of a few figures) automatically spelled One thousand four hundred and ninety-eight only in another cell. Thanks in adv. Hi see: http://www.xldynamic.com/source/xld.xlFAQ0004.html -- Regards Frank Kabel Frankfurt, Germany ron wrote: > I would like to know if there is any way that I can change > numbers/amounts in words form using EXCEL. Eg: $1,498(sum of a few > figures) automatically spelled One thousand four hundred and > ninety-eight only in another cell. T...

Access 2003 and Access 2007 Synchronization
I'm setting up a new business relationship with a company in Portugal. They use Access 2003. I have just bought MS Office Professional 2007 (with Access 2007). Our plan is that they will send, once a month or so, their Access db then we will update and add to that db and then return it after another month or so. There probably won't be a lot of updates on our end so the monthly cycle should work. After they synchronize, they will send a new version of the db and we will start over. My goal is to keep everything as simple as possible partially because I don't know how skillf...

Excel Row to Access Columns
Hi, I have a single row in Excel with a lot of data, what I need to do is move that to a column in Access. I need some way to automate that. I know the easiest way to do that would to just transpose it in excel and then import in access.But I cant do that as I just get that excel file with one row and I need some way to automate the process in Access. thanks m -- mk389 ------------------------------------------------------------------------ mk389's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=15272 View this thread: http://www.excelforum.com/showthread.php?...

Hot link in office outlook 2003 inoperatable
When I click a hot link in my Outlook 2003 I don't get any action, what settings do I need to make this happen, I always could perform this in Outlook Express all versions. Hot Links that are in blue letters. John in Ks ka0mow wrote: > When I click a hot link in my Outlook 2003 I don't get any action, what > settings > do I need to make this happen, I always could perform this in Outlook > Express all versions. Hot Links that are in blue letters. John in Ks You mean a "Hyper link, not a "hot" link. Have you installed IE7? -- Registered Linux User no 24...

Help displaying a random record in a form--Access newbie
Hello, I am new to Access, so if anyone can help me, please assume I know absolutely nothing! I currently have a table with two columns, ID and CHORE. In each row, the ID number corresponds to a chore that I have entered. I would like to create a form with a button and a text field such that when I press the button, a random chore is displayed in the text field (supposed to make chores more "fun" for my son). There is no need to remove this record from future clicks (the same record can come up over and over without any problem for me) Can anyone explain to me (in pai...

Printing single record
HELP! I am using the following code under the ComandButton to print the current report from my form: Dim strWhere As String If Me.Dirty Then 'Save any edits. Me.Dirty = False End If If Me.NewRecord Then 'Check there is a record to print MsgBox "Select a record to print" Else strWhere = "[Num] = " & Me.[Num] DoCmd.OpenReport "Check Request", acViewNormal, , strWhere End If However, I keep getting the following error: The expression On Click you entered as the event property setting produced...

How to remove the Outlook 2003 system tray icon
Hi, Somebody please tell me that there is an option to remove the rather redundant icon Outlook 2003 places in the system tray area! I've been through the options many times but can't seem to find any way of getting rid of it. Thanks muchly Paul You can't get rid of it. You can however hide it. Just right click the Task Bar. Choose Properties. Choose Customize. You can set the Outlook Icon to always hide (in Windows XP only). -- Patricia Cardoza Outlook MVP www.cardozasolutions.com Author, Special Edition Using Microsoft Outlook 2003 ***Please post all replies to the new...

Excel, ODBC and creating queries
Does anyone know of a way to create a query based on values or formula in a spreadsheeet? Thanks in advance, J -- Message posted from http://www.ExcelForum.com From reading between the lines of your post, I am guessing that you have an Access Database with which you want to create a query based on a spreadsheet. If this is the case, you will need to open your database and in the tables section of your databse , right mouse click in the area showing your table names, and select "Link Tables" from the menu. Once you have followed the rest of the steps in the link wizard, a...

Access
Hi My form takes a few moments to load up as it is fairly substantial SQL statement is there a way to get something to display a graphic or 'loading...' message to appear why it calculate the contents? Steve ...

Erro while importing SOP documents using Integration Manager
I've been using Integration Manager to import sales transactions into GP. The procedures and integration has been the same for several years now. Just this morning I started getting the following error message for some of the documents: DOC 2 WARNING: 'Override Shortage' option was selected for quantity shortage on Line 1 for item 666999258259 The integration completes however the system will not allow me to post the batch. I checked a few items associated with the error and there is no quantities on hand however that has not caused a problem in the past. Thanks for you...

Outlook 2003 setup
Thanks for the help so far, everyone. Is there a way to get outlook to send/receive email from a free yahoo account? Ta. Check out this site: http://www.ypopsemail.com/ "cameleonkelle" <cameleonkelle@discussions.microsoft.com> wrote in message news:9FA06750-130F-44EA-B114-063B88DC6FC9@microsoft.com... > Thanks for the help so far, everyone. > Is there a way to get outlook to send/receive email from a free yahoo > account? > Ta. ...

Creating a header using non-contiguous rows
Using Excel 2000 I am using the FILE/Page Setup/Sheet tab/Rows to repeat at top technique to create a header. I currently have $1:$4 in the Rows to repeat at top. I also want to include rows 15 and 16. I have not found a way to do this. Any suggestions? Bernie No way to do this. "Print titles must contiguous and complete rows or columns" is the error message you get when you try to select non-contiguous rows. Gord Dibben Excel MVP On Mon, 23 Aug 2004 07:55:45 -0700, "Bernie Doepkens" <Bdoepken@dbm.state.md.us> wrote: >Using Excel 2000 >I am using the F...

access mail on WEB
Is there a way i can check emails from exchanger server 5.5 from an internet browser. I have Exchange 5.5 in win NT 4.0. Thanks! Yes - install OWA (Outlook Web Access) and open up the needed ports in your firewall (80 for http; better to use SSL and port 443 instead). disk0nek wrote: > Is there a way i can check emails from exchanger server > 5.5 from an internet browser. > > I have Exchange 5.5 in win NT 4.0. > > Thanks! ...

Mail merge to email with an attachment
This is a multi-part message in MIME format. ------=_NextPart_000_004C_01C54401.F8168A50 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable When I had office xp - I was able to very easily email a merged document = and send it automatuically to the relevant contacts in my list as an = attachment. I am using custom forms and fields but it worked = beautifully! After and upgrade to 2003 I find I can no longer do this - word just = hangs - I researched a bit and found business manager could do this - = yes - but not with my custom forms and f...

Money 2003 password problems
Hi, I run Windows XP and Money 2003. I recently moved all my "c:\documents and settings" to another drive, which involved me having to make registry changes so windows knew where the "My documents" and "Shared Documents" had moved to. Everything worked fine, although I had some problems with MS money after the move so I uninstalled it and reinstalled it again (the exact same version). Since I have reinstalled it, the password I used to use to open my money file is not recognised. I am 100% certain that I am using the correct password. I tried using salv.exe to...

Smartlist
Hi I created several smartlist, but the search using the "any" field does not return any results. IT appears to search and but returns nothing. I have using the Integration guide and the only reference to the any field is setting the data type in the Explorer_Get_Datatype script. Is there something I am missing? Do I need to add more code? Is there a data entry I need to delete? Any suggestions? Jason, Tested this on v10 SP3 and I get no results either. It seems to be a bug. Best regards, -- MG.- Mariano Gomez, MIS, MCP, PMP Maximum Global Business, LLC http://www.maximumg...

word 2007 document prints every other line of text.
word 2007 document started printing every other line of type as of yesterday. Document shows okay in print preview, but prints incorrectly. If Print Preview appears OK and you are using an Inkjet printer, I would suspect that you have a problem with the ink nozzles in the printer. -- 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, originally posted via msnews.microsoft.com "bh" <bh@discussions.microsoft.com> wrote in message news:C2A0B201-CA31-4482-B538-B...

access or mount mirrored hard disks
Hi, is it possible to access a mirrored harddrive? or mount the mirrored volume by using api or mfc commands? Thank you in advance Wimpi ...

Access Database In Great Plains
I was wondering if anyone knew how to have the databases that are stored in access transfered over to great plains. I'm current running version 8.0 any help would be greatful. thanks Search Customer Source for integration Manager. MS Access databases can be used as a data source. Vincev "jake" wrote: > I was wondering if anyone knew how to have the databases that are > stored in access transfered over to great plains. I'm current running > version 8.0 any help would be greatful. thanks > > Hi Jake, Is this something you need to do regularly or is it ...