Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


Update Query using VBA does not work consistently

Update Query using VBA does not work consistently

Update Query using VBA does not work consistently

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


  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

- When found, find the original transaction using findrvrs(), mark it


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

RE: Update Query using VBA does not work consistently

What is all the "cr" notation? You didn't mean to use the character function, did you?

If quizzes are quizzical, what are tests?

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close