Re: Using a query as a data source for a mail merge

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



What is the SQL code for the query?

code, before it debugs to say it can't find the database, it asks me to
login as a user.

When you open your database using Access, are you prompted for a (database)
password? Or are you promted for a username and password (workgroup
security)? Or do you start your database using a command line or icon that
specifies either of those two things?

BTW, are you the Cavey Rescue guys in Kent I visited with Brigid & Ralph
last summer? If so, feel free to despam my e-mail and e-mail directly.

Peter Jamieson

"Ultraviolet47" <ultraviolet47@xxxxxxxxxxxxxx> wrote in message
news:1169232300.085832.182700@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hello everyone.

I have used a table as a datasource to mail merge in Word 2003 from
Access 2003. Now I need to change this to a query. I have altered the
code that references the table and changed it to the query name
(Qry_WelcomeLetter), but it says Word cannot find the data source.

Another curious thing that happens is when I execute the merge via this
code, before it debugs to say it can't find the database, it asks me to
login as a user. I have gotten this message previously, but thought
that was because I had not set Word to become visible. I then added the
code to make Word visible and after a few weeks of peace it's asking me
for a user name and password for Admin again?

ANy ideas to stop the username request and how to get it to recognise
the data souce?

Here is my code:

Private Sub Print_Welcome_Letter_Click()
Dim objWord As Object
Set objWord = GetObject("C:\Documents and Settings\Stel\My
Documents\Cavy\Sponsorship pack\Sponsors\welcome letter.doc",
"Word.Document")
' Make Word visible.
objWord.Application.Visible = True
' Set the mail merge data source as the Rat Rescue database.
objWord.MailMerge.OpenDataSource _
Name:="C:\Documents and Settings\Stel\My
Documents\Cavy\Sponsorship pack\Sponsors\CavyRescue.mdb", _
LinkToSource:=True, _
Connection:="QUERY Qry_WelcomeLetter", _
SQLStatement:="SELECT * FROM Qry_WelcomeLetter WHERE SponsorID =
(SELECT Max(SponsorID) FROM Qry_WelcomeLetter)"

objWord.MailMerge.Destination = SendToNewDocument
objWord.MailMerge.Execute

'The following line must follow the Execute statement because the
'PrintBackground property is available only when a document window is
'active. Without this line of code, the function will end before Word
'can print the merged document.

objWord.Application.Options.PrintBackground = False
objWord.Application.ActiveDocument.PrintOut

End Sub



.



Relevant Pages

  • RE: Import external data - web query
    ... The data source I want isn't listed in the Select Data Source dialog box. ... information used to connect to a database. ... I can't create a new data source in Microsoft Query. ... Check your driver First, make sure you have the right ODBC driver (Open ...
    (microsoft.public.excel.misc)
  • Re: Mail Merge
    ... When you connect via DDE, you are always starting a local copy of Access wherever the database is located. ... If you can't even get a DDE connection to a simple local database then I think it's more likely to be a problem on your machine, but that's about as much as I would try to pin it down on the info. available. ... when you are in Open Data Source, ... > can see the listing of table and queries but when I select the query I ...
    (microsoft.public.word.mailmerge.fields)
  • Re: DBMS and lisp, etc.
    ... Naively implemented with SQL, again for 10 ... (1 query for the initial orders, 1 query for each order for its ... soon as you upgrade to the SQL database. ... (eq (order-customer orderA) ...
    (comp.lang.lisp)
  • Re: Mail merge with Access query as source
    ... FWIW I never use Access forms data as a data source so I cannot tell you much more about Word2007+Access2007 accdb+DDE than I can find out with some simple experiments. ... Let's say this query is called XXX. ... if I try to connect programmatically to the same query, is a problem because Word mangles the database pathname if I tell it to open a .accdb but specify a COnnection paramter such as "QUERY XXX". ... I can only get Word 2007 to connect programmtically using DDE if I rename the database so that it has extension .mdb. ...
    (microsoft.public.word.mailmerge.fields)
  • Re: OT: SQL
    ... query processing. ... FROM Employees e, Employees m, Management mgt ... Manager and Employee Salaries. ... The scheme used does not model database files in general, ...
    (sci.logic)