View Single Post
  #5   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Peter Jamieson Peter Jamieson is offline
external usenet poster
 
Posts: 4,582
Default Binary Operation in INCLUDEPICTURE Field

OK, I really meant "use predefined VBA functions etc. in your query". If you
use your own VBA function then you have no option but to use DDE to get the
data. Because that creates other problems it is probably best avoided.

Unfortunately, you cannot use VBA's "and" operator as a bitwise operator
within a Jet SQL query - it is always treated as the logical operator. So
you have to do something like

SELECT (myfield\4) mod 2 AS [mynewfield], *
FROM mytable

Then you should be able to connect via OLE DB (the default - you may still
be able to use ODBC but there are likely to be problems with the file
extension .accdb )

(Just in case you are having problems getting VBA functions to work in SQL
queries, you will probably need to ensure that your database is in a trusted
location to get VBA functions, even when you are working within the database
itself).

Peter Jamieson

"Chris" wrote in message
...
4. Sounds like the cleanest option, so I tried that, and hit another wall.
I created the query, and used calculated fields to create the columns
Image1-8 using a VBA function. I ran into problems using the ODBC, but saw
other messages on this list about using the DDE option instead. I tried to
do
that, but received the following error message:

"Unrecognized database format 'C:\Users\Administrator\Documents\My Data
sources\+Connect to New Data source.odc'.

I also tried to go from access 2007, and "Merge it with Microsoft Word."
I received the following error:
Could not find file 'C:\Dad.mdb'. (The path of the database is
C:\Dad\MergedSales.accdb).

I'll try suggestion 3, but It'd be nice to get this way working.

Thanks a lot for your help so far,
Chris


"Peter Jamieson" wrote:

1. Generally speaking, Word needs to use { = } fields to do calculations
etc.

2. Word's { = } field does not have bitwise operators AFAIK

3. You could try something like

{ INCLUDEPICTURE "{ IF { = mod(round({ MergeField Image }/4,0),2) } = 1
"C:\\pics\\{MergeField ID}-4.jpg" "C:\\pics\\blank.jpg"}" }

(sorry if my arithmetic is wrong, but you get the idea).

4. If you are in a position to create queries in your Access database,
it might be simpler to do the "and 4" operation in a query, either to
return (e.g.) 0 or 1, or to return the complete pathname as an
additional field, then use that query as the data source for your merge.


--
Peter Jamieson

http://tips.pjmsn.me.uk

Chris wrote:
Hello,

I'm trying to initiate a Mail Merge in Word 2007 from an Access 2007
database. In this database, there is an Image column which is actually
just
an integer. I'm using it as a Flag to indicate which of the 8 images
are
actually stored for a particular record. The path creation is rather
simple,
Static_Path\ID-Flag_Bit.jpg.
So, in access, I would normally do something like
If Me!Image And 4 Then
//This image slot is being used
End if

This has worked well for Access. It's efficient and matches the
project's
objectives exactly.
Unfortunately, I can't seem to get it to work in the Mail Merge
process.

I've tried the following with no success:

{INCLUDEPICTURE "{IF {MergeField Image} And 4 "C:\\pics\\{MergeField
ID}-4.jpg" "C:\\pics\\blank.jpg"}" }

The error i receive is:
"A field calculation error occured in record 1."

And the field now reads
{ INCLUDEPICTURE "Error! Unknown op code for conditional." }

To make sure it wasn't just me misunderstanding, I changed And to =,
and the
picture merged fine. This leads me to believe the And is the problem.

So, is there some special trick to getting bitwise operations working
with
mail merge?

Thanks for the help,
Chris