-
Dec 13th, 2012, 09:25 AM
#1
Thread Starter
Junior Member
vba sql query
Hello I posted this in the db section of the forums with no help so I figured I'd try here... I'm writing some vba code that accesses a db. I keep receiving the error posted below. The query works fine with two tables and a where but when I try a join (eventually I will need to add a third table). The query is posted below thanks for the help in advance.
Code:
str = "SELECT CWIPH.CUST_NO, CCSMS.CUST_NO " _
& "FROM CWIPH " _
& "JOIN CCSMS ON CWIPH.CUST_NO=CCSMS.CUST_NO "
JO
-
Dec 13th, 2012, 10:00 AM
#2
Re: vba sql query
Not sure where you're writing the code, but when I use Excel VBA, here's what I get:
Code:
strSQL = "SELECT * FROM tblNames INNER JOIN tblSals ON tblNames.name = tblSals.name" 'works
strSQL = "SELECT * FROM tblNames JOIN tblSals ON tblNames.name = tblSals.name" 'doesn't work
Have you tried using "INNER JOIN" instead?
-
Dec 13th, 2012, 10:09 AM
#3
Thread Starter
Junior Member
Re: vba sql query
Thanks the reply. I updated my query and am now receiving the error below
Code:
str = "SELECT CWIPH.CUST_NO, CCSMS.CUST_NO " _
& "FROM (CWIPH INNER JOIN CCSMS ON CWIPH.CUST_NO = CCSMS.CUST_NO) "
-
Dec 13th, 2012, 12:43 PM
#4
Re: vba sql query
Haven't seen that before, but check this out:
http://support.microsoft.com/kb/964644
-
Dec 13th, 2012, 03:25 PM
#5
Re: vba sql query
does the database you are accessing support joins?
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Dec 14th, 2012, 01:12 PM
#6
Re: vba sql query
Have you tried the suggestion I made in your other thread?
Originally Posted by si_the_geek
OK, well try the really simplified version:
Code:
str = "SELECT CCSMS.CUST_NO " _
& "FROM CSPCL, CCSMS " _
& "WHERE CCSMS.CUST_NO = CSPCL.CUST_NO "
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|