Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.word.mailmerge.fields
FP
 
Posts: n/a
Default Mailmerge, querystring and (un)logical SQL (Word 2003)

Hi,

My name is Feliks, I am from Poland and this is my first post to the
group.
I have the following problem related to mailmerge, QueryString command
and SQL sentence in Word 2003.
In my code I need to perform the following SQL operation with
ActiveDocument.MailMerge.DataSource.QueryString command:

SELECT * FROM x WHERE (field_1 = A OR field _1 = B OR field _1 = C) AND
field _2 = D AND field _3 = E and field_3 =F ORDER BY field_4 ASC

The command is executed without any problems however records retrieved
by the command do not match the above criteria. Instead I get records
which match the following:

SELECT * FROM x WHERE field _1 = A OR field_1 = B OR field _1 = C AND
field _2 = D AND field _3 = E ORDER BY field _4 ASC

In other words parentheses are ignored in this logic sentence and get
completely different set of records as it is supposed to be.

I tried different combinations a) with "(field_1 =A OR ... )" part
at the end (before ORDER), b) with additional parenthesis embracing the
part between WHERE and ORDER etc, the result is always not as expected.

Is there any way to force Word to accept the "parenthesis logic"?
Has anyone a clue how to do it?

I am enclosing the part of my real code which is a subject of my
question (and frustration):

airport_query = " (`Airport` = 'Berlin' OR `Airport` = 'Szczecin' OR
`Airport` = 'Szczecin/Berlin') AND "
st_d = Year(start_dt) & "-" & Month(start_dt) & "-" & Day(start_dt)
en_d = Year(end_dt) & "-" & Month(end_dt) & "-" & Day(end_dt)
vsl = Me.tbVessel.Text

qs = "SELECT * FROM `non-NISSeafarersQuery` WHERE" & airport_query &
"(`VslName` = '" & vsl & "') And (`SignOnDate` = #" & en_d & "#) And
(`SignOnDate` = #" & st_d & "#) ORDER BY `City` ASC"
ActiveDocument.MailMerge.DataSource.QueryString = qs & ""

Any comment will be highly appreciated.

Regards,
FP

 
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:01 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"