?
Solved

Variable will not UPDATE in query

Posted on 2014-11-07
4
Medium Priority
?
176 Views
Last Modified: 2014-11-07
I have  a string variable, d2FedExMemo, that I am trying to update a table with using an UPDATE query.
I can get text and numbers to update this MEMO field in the table but a variable value will not update.
I know that the value I want is in this variable by displaying it prior to the update query being executed.
Value I want is string of item names create:  xxx,yyy,zzz
What am I missing?

Here is my code

    Dim r3 As DAO.Recordset
    Dim d2FedExMemo As String
    Dim d2Invoice As String
    Dim d3Item As String
    Dim d3Invoice As String
   
    Set db = CurrentDb

    Set r = db.OpenRecordset("tblShippingData")
    Set r2 = db.OpenRecordset("tblPackableMaxCube")
    Set r3 = db.OpenRecordset("qryFedExShippingNonPrintMulti")
             
     strSQL = "UPDATE tblShippingData INNER JOIN tblPackableMaxCube ON tblPackableMaxCube.[Invoice #]= tblShippingData.[Invoice #] AND tblShippingData.Item = tblPackableMaxCube.MaxOfItem SET tblShippingData.FedExMem ='" & d2FedExMemo & "'"
    DoCmd.SetWarnings False
           
    r2.MoveFirst
    r3.MoveFirst
   
    If Not (r2.BOF And r2.EOF) Then
       
       Do Until r2.EOF
         r2.Edit
         d2FedExMemo = r2.Fields("FedExMemo").Value
         d2Invoice = r2.Fields("Invoice #").Value
         MsgBox "New invoice" & d2FedExMemo & d2Invoice
         
         Do Until r3.EOF
           
            d3Item = r3.Fields("Item").Value
            d3Invoice = r3.Fields("Invoice #").Value
            'MsgBox d3Item & d3Invoice
            If d3Invoice = d2Invoice Then
               MsgBox "New Item" & d3Item
               d2FedExMemo = d2FedExMemo & ", " & d3Item
               MsgBox "New Memo" & d2FedExMemo
            End If
           
            r3.MoveNext
         Loop
         r2.Edit
         MsgBox "Adding" & d2Invoice & "with" & d2FedExMemo
         'DoCmd.RunSQL strSQL
         db.Execute (strSQL)
         r2.Update
         r2.MoveNext
       
       Loop
    End If
0
Comment
Question by:haident
[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
4 Comments
 
LVL 38

Expert Comment

by:PatHartman
ID: 40428752
Are you getting an error?  Is part of the data updating but not all?

Could there be " or ' characters in the string you are trying to post?
0
 

Author Comment

by:haident
ID: 40428780
No error.  I can load a text value or number but not my variable value. I can load the variable name to update the field.
Only wanting to load  ex...CR1213, CX4444, CSA1213
0
 
LVL 40

Accepted Solution

by:
als315 earned 2000 total points
ID: 40428783
You have static strSQL, because it is assigned before any DO, when your variable is assigned in it. Try to move strSQL=... to the loop before db.Execute (strSQL)
0
 

Author Closing Comment

by:haident
ID: 40428802
Did not think about where it was located.  Thanks!
0

Featured Post

What Is Blockchain Technology?

Blockchain is a technology that underpins the success of Bitcoin and other digital currencies, but it has uses far beyond finance. Learn how blockchain works and why it is proving disruptive to other areas of IT.

Question has a verified solution.

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

The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

764 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