ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   LEFT JOIN sql query (https://www.excelbanter.com/excel-programming/338502-left-join-sql-query.html)

Michael Malinsky[_2_]

LEFT JOIN sql query
 
I am trying to populate a listbox from an access database using a left
join based on the value in a combobox. So if the ComboBox1.ListIndex1
= 1 then I want to retreive those records where FK = 1. My statement
is as follows:

statement = "SELECT tblPageLines.LineNum from tblPageLines LEFT JOIN
tblPages ON tblPageLines.FKPages = " & cbPages.ListIndex + 1

I am getting runtime error -2147217900 (80040e14): Join expression not
supported.

Do I have a syntax problem or is there something more?

Thanks,
Mike.


Rob Bovey

LEFT JOIN sql query
 
Hi Mike,

It looks to me like your join syntax is incorrect. The generalized
syntax for joining two tables in a SQL query is:

FROM Table1 JOIN Table2 ON Table1.Field = Table2.Field

In fact based on your query it's not clear to me why you're trying to
use a left join at all. Because you're selecting one field from the table on
the left side of the join and you aren't referencing the table on the right
side of the join anywhere outside the FROM clause, you should get exactly
the same results with the following SQL statement:

SELECT LineNum FROM tblPageLines WHERE FKPages = " & cbPages.ListIndex + 1

--
Rob Bovey, Excel MVP
Application Professionals
http://www.appspro.com/

* Take your Excel development skills to the next level.
* Professional Excel Development
http://www.appspro.com/Books/Books.htm

"Michael Malinsky" wrote in message
ups.com...
I am trying to populate a listbox from an access database using a left
join based on the value in a combobox. So if the ComboBox1.ListIndex1
= 1 then I want to retreive those records where FK = 1. My statement
is as follows:

statement = "SELECT tblPageLines.LineNum from tblPageLines LEFT JOIN
tblPages ON tblPageLines.FKPages = " & cbPages.ListIndex + 1

I am getting runtime error -2147217900 (80040e14): Join expression not
supported.

Do I have a syntax problem or is there something more?

Thanks,
Mike.




Michael Malinsky[_2_]

LEFT JOIN sql query
 
Thanks, Rob. Apparently I was being too much of a deep thinker on that
one. It makes perfect sense, I just couldn't see it. It works fine
now.

Now it's off to conquer more vba/sql items for my project!

Thanks again.



All times are GMT +1. The time now is 06:23 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com