Solved

Variable will not UPDATE in query

Posted on 2014-11-07
4
169 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
  • 2
4 Comments
 
LVL 34

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 39

Accepted Solution

by:
als315 earned 500 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
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.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

743 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now