Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Update Query using VBA does not work consistently

Status
Not open for further replies.

i2rsantos

Programmer
Joined
Jul 22, 2009
Messages
1
Location
CA
I'm trying to select pairs of records. One is the original transaction, the other is its reversal. So, the only difference between the two records is the amount: one is a positive value the other is its negative value

- loop through a DAO recordset to find a negative amount
Code:
Do
  misvar = False
  misvar = chkmisvar()    'checks for missing info
        
  badDate = False
  badDate = chkbadDate(#1/1/2008#) 'transactions before 2008
           
        If cr(14) < 0 Then      'reversed transaction
                         
            markProcessed (17)  'mark as invalid record
            misc = findrvrs()   'find reversed record 
            cr.MoveNext

- When found, find the original transaction using findrvrs(), mark it
Code:
Public Function findrvrs() As Boolean
Dim strWhere  As String
Dim strUpdate As String
Dim strSQLQuery As String

    amt = -1 * cr(14) 'set amount to positive
    'famt = Format(amt, "#,##0.00")
    
    strUpdate = "UPDATE [" & tripDBName & "] SET [" & tripDBName & "].Processed = 1"
    
    strWhere = " Where [" & tripDBName & "].HCP = " & cr(4) & " AND " & _
    "[" & tripDBName & "].Departure = #" & cr(5) & "# And " & _
    "[" & tripDBName & "].Origin LIKE " & Chr(34) & cr(7) & Chr(34) & " And " & _
    "[" & tripDBName & "].Destination LIKE " & Chr(34) & cr(8) & Chr(34) & " And " & _
    "[" & tripDBName & "].CoPayment = " & amt & " And " & _
    "[" & tripDBName & "].Case = " & cr(12)
    
    'Debug.Print strWhere
    
    strSQLQuery = strUpdate & strWhere
    Set qrydef = db.CreateQueryDef("", strSQLQuery)
    qrydef.Execute
    
End Function

The above works but the results are inconsistent. See URL below to image file. The records marked in green is where the code works. Those in red should have worked, but didn't.


- Before this I tried DAO Find/Update same results.
- Tried closing Access completely and trying again, no luck.
- Does not work on the same records.
 
What is all the "cr" notation? You didn't mean to use the character function, did you?

If quizzes are quizzical, what are tests?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top