SQL code won't work in Excel VBA

Viewed 443

I am using Excel 2010 VBA and querying 3 tables from a PGSQL database

The following SQL code works perfect in MS ACCESS:

SELECT user.surname,user.forename,recall.recalldate,telephone.number
FROM (user INNER JOIN recall ON user.entity_id = recall.master_id) 
LEFT JOIN Telephone ON recall.master_id=Telephone.master_id

but doesn't seem to transfer to EXCEL VBA:

Dim RECALL As String
RECALL = "SELECT user.surname,user.forename,recall.recalldate,telephone.number " _
        & "FROM (user INNER JOIN recall ON user.entity_id = recall.master_id) " _
        & "LEFT JOIN Telephone ON recall.master_id=Telephone.master_id " _

Set rs = conn.Execute(RECALL)
With ActiveSheet.QueryTables.Add(Connection:=rs, Destination:=Range("A1"))
  .Refresh
End With

I get a runtime error: ...expected table source after FROM, got(

The user table links to the recall table using user.entity_id = recall.master_id and shows all recall records for users. Then I need the telephone numbers for the matched users. Not all will have a tel number, but I need all recalls regardless of whether they have a tel number.

What is wrong with the SQL code in VBA?

2 Answers
Related