Left Joins with Multiple Conditions in VBA

Hello,

I am trying to run a query in Excel VBA. The query has a left join with a two conditions -- every time I run it excel crashes. If I remove the brackets enclosing the two conditions, the query fails.

The query itself is correct because if I run it directly in Oracle it works. Also I can run it thru excel via Date->Import External Data but not thru VBA.

Also if I restrict myself to one condition instead of two it works thru VBA.

Any one have any insights into what the problem could be? Or any proposed workaround... Thanks in advance.

Saleem


Dim db As Database

Set db = OpenDatabase("", dbDriverPrompt, False, "ODBC;DSN=FM;")

Query = "select VCI.isec_id, VCI.inst_class, CVL_IDENT_BB.EXT_IDENT, VCI.pl_ccy as CCY " _
& "from V_CONT_INMK VCI " _
& "left join IDENTIFIER CVL_IDENT_BB on (CVL_IDENT_BB.tdp_id = VCI.isec_id and " _
& "CVL_IDENT_BB.ident_type = " & Chr(39) & "BB_TCM" & Chr(39) & ") " _
& "where VCI.inst_class in (" & Chr(39) & "ORD" & Chr(39) & ", " & Chr(39) & "DR" & Chr(39) & ", " & Chr(39) & "CFD" & Chr(39) & ")"

Dim FM As Recordset

Set FM = db.OpenRecordset(Query, dbOpenDynaset, dbSeeChanges, dbReadOnly)
[1305 byte] By [saleem145] at [2007-12-20]
# 1

May seem kind of off but you should try to find out at what line Excel is crashing at. Probably the easiest way but hackiest way to do this is to put a MsgBox("Phase 1") after each line to see exactly what line its crashing on. E.g. is it crashing upon opening the record set? before that. etc

MarcD at 2007-9-9 > top of Msdn Tech,Microsoft ISV Community Center Forums,Visual Basic for Applications (VBA)...
# 2

Its the OpenRecordset line that crashes. Thanks.

Saleem

saleem145 at 2007-9-9 > top of Msdn Tech,Microsoft ISV Community Center Forums,Visual Basic for Applications (VBA)...
# 3
Have you tried a simple query. I'd try to trim as much of that query down as possible and see at what point it is crashing. E.g. does all queries crash or is it that specific one. And if so what part of it is causing it.
MarcD at 2007-9-9 > top of Msdn Tech,Microsoft ISV Community Center Forums,Visual Basic for Applications (VBA)...
# 4

Hello,

It is the left join with multiple conditionss that is causing the problem. Specifically

"left join IDENTIFIER CVL_IDENT_BB on (CVL_IDENT_BB.tdp_id = VCI.isec_id and " _
& "CVL_IDENT_BB.ident_type = " & Chr(39) & "BB_TCM" & Chr(39) & ") "

If I just left join on one condition it works. Specically

"left join IDENTIFIER CVL_IDENT_BB on CVL_IDENT_BB.tdp_id = VCI.isec_id"

The left join with mutliple conditions query does work when tried directly via Oracle and it also works when tried thru Excel Tools Import Data. Just doesn't work thru VBA.

Thanks for your help.

Saleem

saleem145 at 2007-9-9 > top of Msdn Tech,Microsoft ISV Community Center Forums,Visual Basic for Applications (VBA)...
# 5

When you import through Excel import Data do you use a specific method? like some ODBC or Oracle method ? that isn't the same when you connect to it with your DNS? Also how many rows does the query return? have you tried to make it return a very small amount with the TOP 5 or top 1 clause ?

MarcD at 2007-9-9 > top of Msdn Tech,Microsoft ISV Community Center Forums,Visual Basic for Applications (VBA)...
# 6

from the support engineer:

According to your problem, I want you try “"left join IDENTIFIER CVL_IDENT_BB on CVL_IDENT_BB.ident_type = " & Chr(39) & "BB_TCM" & Chr(39) & "”. It’s the second condition of your left join. Tell me your result and I will follow up it with you.

And MarcD post the question” When you import through Excel import Data do you use a specific method? like some ODBC or Oracle method ? that isn't the same when you connect to it with your DNS? Also how many rows does the query return? have you tried to make it return a very small amount with the TOP 5 or top 1 clause ?” I also want to know your answer. Thanks, that’s will help us find the root cause.

-brenda (ISV Buddy Team)

MSISVBuddyTeam at 2007-9-9 > top of Msdn Tech,Microsoft ISV Community Center Forums,Visual Basic for Applications (VBA)...
# 7

Brenda,

The way I import data directly into excel is to go to Data->Import External Data->New Database Query. From this menu I select the ODBC connect to the Oracle database and use exactly the same query as I am using from VBA.

When I execute the same SQL query from VBA code is executed correctly up to the line involving the query. After which the function returns with a value error.

The result set is only a few records so size of results is not the issue.

Saleem

saleem145 at 2007-9-9 > top of Msdn Tech,Microsoft ISV Community Center Forums,Visual Basic for Applications (VBA)...