Solved

Variable will not UPDATE in query

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

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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Suggested Solutions

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

778 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