dbTalk Databases Forums  

Query Syntax Problem

comp.databases.ms-access comp.databases.ms-access


Discuss Query Syntax Problem in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Andi Plotsky
 
Posts: n/a

Default Query Syntax Problem - 01-03-2005 , 11:44 PM






Can someone please tell me - what's the problem with the syntax of the
Select portion of the call to the ChangeQueryDef function. My " " marks are
off - but I can't figure out where -

Private Sub cboSelectPhys_Change()
Dim rsA As DAO.Recordset
Dim strSQL As String

'select the records which have the same Full dr's name as that
'selected in the combobox
Set rsA = CurrentDb.OpenRecordset("Select * from qryLkpPhys where [Physician
Name]= '" & cboSelectPhys.Value & "'", dbOpenDynaset)

rsA.MoveFirst
rsA.MoveLast
Debug.Print "recordcount= "; rsA.RecordCount
If rsA.RecordCount > 0 Then
rsA.MoveFirst
strSQL = "'" & rsA("MD#") & "'"
rsA.MoveNext
Do Until rsA.EOF
strSQL = strSQL & " OR '" & rsA("MD#") & "'"
rsA.MoveNext
Loop
End If
Debug.Print "strSql= "; strSQL

ChangeQueryDef "qryPhysRpt", "SELECT Docname, Patient,Q6 from qryPhysName
where Q12=(" & "'" & strSQL & "')" _
& " OR Q13=(" & "'" & strSQL & "')" & _
" OR Q14=(" & "'" & strSQL & "')" & _
" OR Q15=(" & "'" & strSQL & "')"

Thanks!
Andi





Reply With Quote
  #2  
Old   
jimfortune@compumarc.com
 
Posts: n/a

Default Re: Query Syntax Problem - 01-04-2005 , 01:38 AM






Andi Plotsky wrote:
Quote:
Can someone please tell me - what's the problem with the syntax of
the
Select portion of the call to the ChangeQueryDef function. My " "
marks are
off - but I can't figure out where -

...
Thanks!
Andi
Here's what I tried:

I changed the creation of strSQL to use commas instead of OR's.

where Q12 IN (" & strSQL & ")" & " OR Q13 IN (" & strSQL & ")" & ...

created:

where Q12 IN ('12','15') OR Q13 IN ('12','15') ...

Note that if Q12 and Q13 are Long fields you should create strSQL so
that the final string looks like:

where Q12 IN (12,15) OR Q13 IN (12,15) ...
These queries ran correctly in my test examples.

James A. Fortune



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.