Append Query problem

  • Thread starter ionic-fire via AccessMonster.com
  • Start date
I

ionic-fire via AccessMonster.com

I have created an append query in vba code which is inside a For...Next loop.
I create an SQL statement to find matching related records in one table, and
then insert these matching records into a temporary table. I repeat for each
value of unique primary key that is provided (in an array).

The issue I have is that the append query only works for the first matching
record, not the subsequent records. I have verified that correct SQL
statements are generated during each iteration of the loop, but for some
reason no inserts occur after the first one. The temp table is cleared at the
beginning of the subroutine.

Any input would be helpful, I thank you very much for any assistance.


Here is my code:
====================
If boolNoRecords = False Then 'the "No Records Found" flag is not set.

For x = 0 To UBound(lngArrayTestID)
If lngArrayTestID(x) > 0 Then 'do not allow TestID = 0
condition

'lngArrayTestID() contains non-duplicated testID values
(primary key).

strTempSQL1 = "INSERT INTO " & strResultsTable

strTempSQL1 = strTempSQL1 & " SELECT * FROM "
strTempSQL1 = strTempSQL1 & strSourceQuery2 & " WHERE "
strTempSQL1 = strTempSQL1 & "TestID = " & lngArrayTestID(x)

DoCmd.SetWarnings False 'turn off warnings
DoCmd.RunSQL strTempSQL1 'execute "INSERT INTO" query
DoCmd.SetWarnings True 'turn on warnings


End If
strTempSQL1 = "" 'make sure it is cleared before starting

Next x 'repeat the process for all TestID values in
lngArrayTestID()
End If 'end the If boolNoRecords = False clause
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top