473,387 Members | 1,573 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Error 3021 in SQL using multiple INNER JOINS.

I created a query in the Access Query Builder that I modified to use with VBA Code so I could reuse it for any record I choose. The one that I created with the Access Query builder works beautifully with the hardcoded criteria. The VBA version with my criteria being set by a variable returns Error 3021.
I am using a DAO Recordset and all I want to do is retrieve the data to place into a report.

The Original made in the Access Query Builder:
Expand|Select|Wrap|Line Numbers
  1. SELECT *
  2. FROM (((tbl_Reject INNER JOIN tbl_Serial_Number ON tbl_Reject.[Reject_Number(PK)] = tbl_Serial_Number.[Reject_number(FK)]) INNER JOIN tbl_Approvals ON tbl_Reject.[Reject_Number(PK)] = tbl_Approvals.[Reject_Number(FK)]) INNER JOIN tbl_Expeditor_Defect_Type ON tbl_Reject.[Reject_Number(PK)] = tbl_Expeditor_Defect_Type.[Reject_number(FK)]) INNER JOIN tbl_Inventory_Reason_Code ON tbl_Reject.[Reject_Number(PK)] = tbl_Inventory_Reason_Code.[Reject_number(FK)]
  3. WHERE (((tbl_Reject.[Reject_Number(PK)])=250189));
  4.  
The modified version for VBA:
Expand|Select|Wrap|Line Numbers
  1. strSQL_Edit_Record = "SELECT * FROM (((tbl_Reject INNER JOIN tbl_Serial_Number ON tbl_Reject.[Reject_Number(PK)] = tbl_Serial_Number.[Reject_number(FK)])" & _
  2. " INNER JOIN tbl_Approvals ON tbl_Reject.[Reject_Number(PK)] = tbl_Approvals.[Reject_Number(FK)])" & _
  3. " INNER JOIN tbl_Expeditor_Defect_Type ON tbl_Reject.[Reject_Number(PK)] = tbl_Expeditor_Defect_Type.[Reject_number(FK)])" & _
  4. " INNER JOIN tbl_Inventory_Reason_Code ON tbl_Reject.[Reject_Number(PK)] = tbl_Inventory_Reason_Code.[Reject_number(FK)]" & _
  5. " WHERE (((tbl_Reject.[Reject_Number(PK)])=" & lngEditCriteria & "));"
  6.  
Any ideas? Thanks in advance.

Steve
Jan 20 '09 #1
4 3327
DonRayner
489 Expert 256MB
Is there a posibility that your lngEditCriteria variable is null?
Jan 21 '09 #2
No, I used the same data in the VBA one that I had hardcoded in the Access Builder. I have a message box that shows the SQL for debugging and it is there. This has me puzzled.

Steve
Jan 21 '09 #3
NeoPa
32,556 Expert Mod 16PB
Can you please provide the error message as well as the code used to execute your SQL.

I can confirm that the SQL resolves to essentially the same SQL as that provided by the Query Builder.

Also, assuming [lngEditCriteria] is Dimmed as Long (which I assume) then it won't contain a null or any invalid value (It may not match a record - but won't be invalid).

Welcome to Bytes!
Jan 21 '09 #4
I found it. It was actually in my code.

Original:
Expand|Select|Wrap|Line Numbers
  1. Do Until a = iQty
  2.     strErrSect = " [Fill_Record ME-Manufacturing Engineer D2] "
  3.     BigLine = BigLine & "Serial #: " & !Part_serial_number & c5SP & "Date Code: " & !Date_code & cDCF
  4.     MsgBox "BIGLINE [" & a & "]: " & BigLine, , strErrSect
  5.     a = a + 1
  6.     rs.MoveNext (This moved to a record that did not exist once the count was reached)
  7. Loop
Changed to:
Expand|Select|Wrap|Line Numbers
  1. Do Until a = iQty
  2.     strErrSect = " [Fill_Record ME-Manufacturing Engineer D2] "
  3.     BigLine = BigLine & "Serial #: " & !Part_serial_number & c5SP & "Date Code: " & !Date_code & cDCF
  4.     MsgBox "BIGLINE [" & a & "]: " & BigLine, , strErrSect
  5.     a = a + 1
  6.     If a <> iQty Then
  7.     rs.MoveNext
  8.     End If
  9. Loop
Thanks for all of your help.

Steve
Jan 21 '09 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Ilan Sebba | last post by:
When it comes to adding records in related tables, Access is really smart. But when I try to do the same using ADO, I am really stupid. Say I have two parent tables (eg Course, Student) and one...
9
by: Robert Wing | last post by:
I support an MS Access application in which errors are trapped using the On Error statement. Just recently, the users of this system have experienced run-time error number 3021 on a random basis. ...
2
by: Colleyville Alan | last post by:
I want to extract some records that are common to three tables, but not contained in the fourth. Following what I have see in the archives and also trying the unmatched records query wizard, if I...
2
by: Polly | last post by:
I'm trying to write the results of a query, a name, ID number, and date out to a notepad .txt file to print on a "legacy" printer. I get the output from the first 2 "write" lines over the...
6
by: dmonroe | last post by:
hi group -- Im having a nested inner join problem with an Access SQl statement/Query design. Im running the query from ASP and not usng the access interface at all. Here's the tables: ...
4
by: Sascha.Moellering | last post by:
Hi, the following SQL-Statement does not compile, I receive SQL0338N as an error. The erroneous parts of the statement are the left-outer-Joins, but I don't know how to solve the problem, any...
2
by: narendra vuradi | last post by:
Hi I have a requirement where in i haev to convert the SQL from Oracle to the one which will run on the SQL server. in the Oracle Query i am doing multiple joins, between some 13 tables. and...
1
by: rando1000 | last post by:
I've got a query from SQL Server that I'm trying to carry over to Access. The Query uses 3 tables with two INNER JOINS, and each of the INNER JOINS has two operators, roughly like this: Select...
3
by: modernshoggoth | last post by:
G'day all, I'm trying to update a single table (containing plans for flights) with information from the same and other tables (containing info for organisations and locations). tblFlightPlans...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.