View Single Post
  #2   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Peter Jamieson Peter Jamieson is offline
external usenet poster
 
Posts: 4,582
Default Is it possible to use a query that is based on a function in a mail merge?

To use "User-defined" Access functions in a data source, you have to connect
to the data source using the DDE method, not OLEDB (the default in Word 2002
and later).

In Word 2002/2003, check Word Tools-Options-General-Confirm conversaions
at open, then
a. go through the process of connecting to your data source again
b. after you have selected the file in the "Select Data Source" dialog box
and clicked "Open", you should see an additional dialog box titled "Confirm
Data Source"
c. select "MS Excel Worksheets via DDE (*.xls)" and click OK.

In Word 2007, use much the same process but start by checking Office
button-Word Options-Advanced-General-Update Automatic Links at Open.

I'm not so sure this works the same way in Word 2007. Also, Access has to be
running for this to work.

The other approach is in essence to generate the data you need first, then
connect to that - e.g. you can export to another file, or probably use a
CREATE TABLE query of some kind within Access. But then you have to do that
as a separate step.

--
Peter Jamieson
http://tips.pjmsn.me.uk

"Shimon" wrote in message
...
I have a word docment that imports data from access. When the query is
bases on a number it wrks fine, but when I use a function in the query,
word responds with an error and cannot open the data source.

SELECT qselItem_List.*, qselItem_List.ReadyForTranslating
FROM qselItem_List
WHERE ( ((qselItem_List.SaleID) CurrentAuctionNumber()))
ORDER BY qselItem_List.AutoNumber;

Here is the function that the query uses.


Public Const stCurrentAuctionNumber = 45
Public Static Function CurrentAuctionNumber() As Double
Static currAuctionNumber As Double
If tempCurrAuctionNumber = 0 Then
CurrentAuctionNumber = stCurrentAuctionNumber
tempCurrAuctionNumber = stCurrentAuctionNumber
Else: CurrentAuctionNumber = tempCurrAuctionNumber
End If
End Function

I would like to use this function, so that I can change the criteria from
tim to time by using the setCurrentAuctionNumber

Public Static Function SetTempAuctionNumber(dAuctionNumber)
tempCurrAuctionNumber = dAuctionNumber
End Function

Thanks for any help,
Shmon