[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

SQL & VBA

Posted on 2011-03-14
3
Medium Priority
?
281 Views
Last Modified: 2012-06-21
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.

Paula
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
        rs1.MoveFirst
        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
            
            rs1.MoveNext
        Loop
            'MsgBox rlst2
    End If

Open in new window

0
Comment
Question by:Monterey
[X]
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
  • 2
3 Comments
 
LVL 77

Accepted Solution

by:
peter57r earned 2000 total points
ID: 35130707
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.
0
 

Author Comment

by:Monterey
ID: 35130765
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!

Paula
0
 

Author Closing Comment

by:Monterey
ID: 35130769
Quick response...answered the question exactly!  Brilliant!
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

As they say in love and is true in SQL: you can sum some Data some of the time, but you can't always aggregate all Data all the time! Introduction: By the end of this Article it is my intention to bring the meaning and value of the above quote to…
Introduction Hopefully the following mnemonic and, ultimately, the acronym it represents is common place to all those reading: Please Excuse My Dear Aunt Sally (PEMDAS). Briefly, though, PEMDAS is used to signify the order of operations (http://en.…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

650 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