Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

SQL problem in VB5

Posted on 2000-03-08
5
180 Views
Last Modified: 2010-05-02
My VB prog executes two or so SQL queries in succession. Originally the results of the first SQL statement were written to a WORKTABLE1 (in the 'host' MDB file) and the second SQL statemment used this WORKTABLE1 as part of the source for the second SQL query that attempted to write the results of that query to a second WORKTABLE2 again in the 'host' MDB file.

This worked (I know I could have used recordsets, but I wanted to stick reasonably closely to the SQL-approach)

The problem arises when I try to create/read from WORKTABLES created in a second 'scratch' MDB file...ie
 query one...
SELECT  Company.company,  [job table].[Job No]  
INTO WorkTable1 IN C:\Scratch.mdb
FROM Company
INNER JOIN   [job table]
ON  Company.Company_ID=[Job Table].[Customer ID]
WHERE [Job table].CompDate is not null ;  
 query two...
SELECT WorkTable1.company,FORMAT( sum([Quoted_Items].[Total Price]),'0.00')  AS TotalValue  
INTO WorkTable2 IN C:\Scratch.mdb
FROM  WorkTable1 IN C:\Scratch.mdb
INNER JOIN [Quoted_Items]
ON   [Quoted_Items].Jobid= WorkTable1.[Job No]
GROUP BY WorkTable1.company;

Query two returns a 'Syntax error in FROM clause'

It is the 'second' WORKTABLE2 that causes the problem (the approach works OK when only WORKTABLE1 is involved)

Similarly, the following SQL structure also gives rise to the same 'syntax error in FROM clause' message....

SELECT WorkTable1.Dealing, Staff.Fullname,   FORMAT(WorkTable1.TotalValue,'£0.00')
FROM WorkTable1 IN C:\Scratch.mdb
INNER JOIN Staff
ON Staff.Initials = WorkTable1.Dealing;


Any help appreciated,
Garry
0
Comment
Question by:grh
  • 2
  • 2
5 Comments
 
LVL 4

Expert Comment

by:wqw
ID: 2595763
make sure you qoute you pathnames this way:

SELECT WorkTable1.company,FORMAT( sum([Quoted_Items].[Total Price]),'0.00')  AS TotalValue  
INTO WorkTable2 IN 'C:\Scratch.mdb'
FROM  WorkTable1 IN 'C:\Scratch.mdb'
INNER JOIN [Quoted_Items]
ON   [Quoted_Items].Jobid= WorkTable1.[Job No]
GROUP BY WorkTable1.company;

HTH,

</wqw>
0
 
LVL 2

Expert Comment

by:p_biggelaar
ID: 2595799
The reason why it shouldn't work (so if wgw's proposed answer works, I'd be pleasantly surprised) is because using IN dbname requires you that all the tables (including the ones you're joining) are to be found in the same database.

In other words, IN should be placed after the join and furthermore it expects to find the tables 'quoted_items' and 'staff' in the C:\scratch.mdb
0
 
LVL 2

Accepted Solution

by:
p_biggelaar earned 100 total points
ID: 2595803
The reason why it shouldn't work (so if wgw's proposed answer works, I'd be pleasantly surprised) is because using IN dbname requires you that all the tables (including the ones you're joining) are to be found in the same database.

In other words, IN should be placed after the join and furthermore it expects to find the tables 'quoted_items' and 'staff' in the C:\scratch.mdb
0
 
LVL 4

Expert Comment

by:wqw
ID: 2595856
p_biggelaar: true

so you are implying the (s)he should fetch both table in the temp mdb and join them there

</wqw>
0
 

Author Comment

by:grh
ID: 2612538
Thanks, the advice helped and saved me spending time looking for another solution.
Garry
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Excel VBA combine two working workbooks 8 60
Adding to a VBA? 6 78
Error when passing an argument to a vb6 that contains  '/' 7 40
vbModal 12 57
There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question