Run-Time Error 3131 Syntax error in FROM clause (1 Viewer)

m_sami9

New member
Local time
Today, 11:37
Joined
Feb 2, 2020
Messages
13
I'm facing problem about Run-Time Error 3131 Syntax error in FROM clause.

Please help me to resolve the problem.

Code:
    CurrentDb.Execute " INSERT INTO tblTestReport (TestDetailID, TestID, ReceiptID, ParticularsID, PARTICULARS, RESULT, UNITS, MALE, FEMALE, ABNORMAL, PartHead, PartHeadID) " _
        & " SELECT TestDetailID, TestID, ReceiptID, ParticularsID, PARTICULARS, RESULT, UNITS, MALE, FEMALE, ABNORMAL, PartHead, PartHeadID " _
        & " FROM tblSampleReceipts2 (tblTestDesc INNER JOIN tblTestParticulars ON tblTestDesc.TestID = tblTestParticulars.TestID) INNER JOIN tblTestDetails2 ON tblTestDesc.TestID = tblTestDetails2.TestID WHERE ReceiptID = '" & ReceiptID & "'"
 

Minty

AWF VIP
Local time
Today, 07:37
Joined
Jul 26, 2013
Messages
10,371
Put the SQL into a string variable and debug.print it in the immediate window.
Get into the habit of doing this for all but the simplest constructions of SQL strings.

Then paste it into the query editor, it should highlight what it can't work out.
 

cheekybuddha

AWF VIP
Local time
Today, 07:37
Joined
Jul 21, 2014
Messages
2,280
Hi,

tblSampleReceipts2 is not correctly joined - it has no JOIN clause or ON clause.

Does it need to be there at all?

If it does need to be included, then re-create the SELECT portion of the query in the query designer and copy the SQL here, and we can help you get it into a string variable
 

m_sami9

New member
Local time
Today, 11:37
Joined
Feb 2, 2020
Messages
13
Hi,

tblSampleReceipts2 is not correctly joined - it has no JOIN clause or ON clause.

Does it need to be there at all?

If it does need to be included, then re-create the SELECT portion of the query in the query designer and copy the SQL here, and we can help you get it into a string variable
Code:
    CurrentDb.Execute "INSERT INTO tblTestReport ( TestDetailID, TestID, ReceiptID, ParticularsID, PARTICULARS, RESULT, UNITS, MALE, FEMALE, ABNORMAL, PartHead, PartHeadID ) " _
        & " SELECT tblTestDetails2.TestDetailID, tblTestDetails2.TestID, tblTestDetails2.ReceiptID, tblTestParticulars.ParticularsID, tblTestParticulars.PARTICULARS, tblTestParticulars.RESULT, tblTestParticulars.UNITS, tblTestParticulars.MALE, tblTestParticulars.FEMALE, tblTestParticulars.ABNORMAL, tblTestParticulars.PartHead, tblTestParticulars.PartHeadID " _
        & " FROM tblSampleReceipts2, (tblTestDesc INNER JOIN tblTestParticulars ON tblTestDesc.TestID = tblTestParticulars.TestID) INNER JOIN tblTestDetails2 ON tblTestDesc.TestID = tblTestDetails2.TestID " _
        & " WHERE ReceiptID =  " & ReceiptID & " ;"
 

cheekybuddha

AWF VIP
Local time
Today, 07:37
Joined
Jul 21, 2014
Messages
2,280
Adding the comma might fix your query, but will it give you the result you want - it will create a cartesian product (but will be limited by the WHERE clause).

Since we have no idea of your tables and their structure it's impossible to comment.

Have you got the result you want now?
 

m_sami9

New member
Local time
Today, 11:37
Joined
Feb 2, 2020
Messages
13
Adding the comma might fix your query, but will it give you the result you want - it will create a cartesian product (but will be limited by the WHERE clause).

Since we have no idea of your tables and their structure it's impossible to comment.

Have you got the result you want now?
 

Attachments

  • Capture1.PNG
    Capture1.PNG
    29.5 KB · Views: 43

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 23:37
Joined
Oct 29, 2018
Messages
21,473
Can you create your APPEND query using the query designer? If you can, you can either execute that query or take its SQL and paste it in your code.
 

Users who are viewing this thread

Top Bottom