View Single Post
  #20   Report Post  
Posted to microsoft.public.mac.office.word,microsoft.public.word.mailmerge.fields
Peter Jamieson
 
Posts: n/a
Default fields queries and utter disaster

As a workaround in Office 2004, the following general approach can be used
to get data via Excel. However, I am very unfamiliar with VBA on the Mac
platform and the Excel objects this macro needs, so if you want to pursue
this, you may need more expert help than I can give. In particular, I
originally tried to modify the QueryTable connection and sql from this
macro, but however I tried to do it, Word crashed, so I opted for the
simpler approach below. Also, on Mac I don't know of a way to prevent Word
from prompting for the Worksheet/range details whenever it tries to update
the DATABASE field.

1. Create a new workbook (let's call it "Macintosh
HD:Users:meocuments:query.xls")
2. Use the data menu to insert the results of a query in Sheet1 at cell A1.
You can delete Sheets2 and 3 if you like.
3. Save and close the workbook.

4. In Word, use the database toolbar insertion feature to insert the .xls as
a DATABASE field

5. In Word's VBA editor, use Tools|References to make a reference to the
Excel object.

Create a sub as follows:

Sub GetODBCDataViaExcel()
Dim objExcel As Excel.Application
Dim objWorkBook As Excel.Workbook
Dim strWorkbookName as String

strWorkbookName = "Macintosh HD:Users:meocuments:query.xls"

' open the spreadsheet, refresh the table, and save the sheet
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open(strWorkbookName)
objWorkbook.Worksheets(1).QueryTables(1).Refresh
objWorkbook.Close savechanges:=True
set objWorkbook = Nothing
objExcel.Quit
Set objExcel = Nothing

' Update all the fields in the body of the active Word document

ActiveDocument.COntent.Fields.Update

End Sub

It may also be worth looking at the following in Office.X:
Assuming you went through MS Query to set up the query, did your version of
MS Query allow you to save the query definition before returning the data to
Excel, or does it allow you to open a query definition file? On the Windows
version, (a) this is feasible and MS Query lets you save a .dqy or .qry file
which can be used by Word and (b), MS Query can be run as a standalone
program, but on the Office 2004 version of MS Query, it only appears to be
possible to start Query from Excel, and there is no facility to save/open
separate query definition files. I have tried creating one by hand just in
case the facility has been retained elsewhere but that doesn't work either.

Peter Jamieson

"consiglieri" wrote in message
oups.com...
OK,
Yes looking back on my posts I realize I my answers may have been
somewhat befuddled. But I have not managed to get a direct mysql query
into word, only via excel.

Guess I will keep trying to find a reasonable solution.