Solved

Variable will not UPDATE in query

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MS Access 2016 Debugging 7 42
view mode vs edit mode 17 47
TRIM a textbox value MS Access 10 23
VBA to alter Table in MS Access .mbd (2000-2003) database 5 27
It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

914 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

20 Experts available now in Live!

Get 1:1 Help Now