Hello All,
I am going to try to explain this the best way I know how.  I am inserting data into a table from a query via SQL.  Before I run the SQL, I am trapping a value in another table.  I then need to get that trapped value into the table from SQL as it builds the records. That trapped value will change from record to record.  My code is below and the InvoiceNo is the trapped value that I need to insert.  Hope that makes sense...Thank you so much in advance.

Dim sqltext2 As String
Dim rlst2 As String
Dim strFac As String
Dim strPO As Integer
Dim strInv As String
    CurrentDb.Execute "DELETE * FROM [tblLawsonStep2]", dbFailOnError
    CurrentDb.Execute "DELETE * FROM [tblReconTemp]", dbFailOnError
    DoCmd.OpenQuery "qryRecontoTempRecon"
    Set rs1 = CurrentDb.OpenRecordset("SELECT * FROM [tblReconTemp]")
    If Not rs1 Is Nothing Then
        Do While Not rs1.EOF
            rlst2 = ""
            rlst2 = Chr(34) & rs1.Fields("[ReceiverNo]").Value & Chr(34)
            strFac = rs1.Fields("[Facility]").Value
            strPO = rs1.Fields("[PO]").Value
            strInv = rs1.Fields("InvoiceNo").Value
            rlst2 = Mid(rlst2, 2, Len(rlst2) - 2)
            'MsgBox rlst2
            sqltext2 = "INSERT INTO [tblLawsonStep2] SELECT * FROM [qryReceivedAllLawson]" & _
            " WHERE (((qryReceivedAllLawson.Facility)= " & strFac & ") AND ((qryReceivedAllLawson.[PO#])= " & strPO & ") AND ((qryReceivedAllLawson.ReceiverNo) In (" & rlst2 & ")));"
            'MsgBox sqltext2
            DoCmd.RunSQL sqltext2
            'MsgBox rlst2
    End If

Open in new window

Who is Participating?
I'm not sure I have understood correctly but it seems like you should use..

 sqltext2 = "INSERT INTO [tblLawsonStep2] SELECT *, '" & strinv & "' FROM [qryReceivedAllLawson]" & _

Backup before testing.
MontereyAuthor Commented:
OMG - that did it!  Brilliant...thanks so much...one thing I had to add was the field that I wanted the value to go into...

"INSERT INTO [tblLawsonStep2] SELECT *, '" & strInv & "' AS InvoiceNumber FROM [qryReceivedAllLawson]" & _

Thanks for the quick response, it is greatly appreciated!

MontereyAuthor Commented:
Quick response...answered the question exactly!  Brilliant!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.