Solved

Variable will not UPDATE in query

Posted on 2014-11-07
4
173 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 36

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 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
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.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

733 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