INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

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!

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

Jobs

Deleted record in recordset reappears when recordset used as report datasource

Deleted record in recordset reappears when recordset used as report datasource

Deleted record in recordset reappears when recordset used as report datasource

(OP)
I generate an unmatched query in my vba code. I then open the recordset in vba to determine if I need to remove one of the records I don't want to appear in the subsequent report.

Here's the code snippet I use: Emp comes over as a parameter in this function, named ChkJobCodes.
The "qryMonthJobCodes Without Matching tblJobs" query is created earlier in the function

CODE

Dim rs as DAO.Recordset
        Dim i as Integer, rcnt as Integer
        Dim JCd as String

        Set rs = db.OpenRecordset("qryMonthJobCodes Without Matching tblJobs", dbOpenDynaset)
        rs.MoveLast
        If rs.RecordCount > 0 Then                                      
        
            rs.MoveFirst
            If Emp = "Tal" Then                                         
                For i = 1 To rs.RecordCount
                    JCd = rs.Fields(0).Value
                    If Left(JCd, 6) = "unassi" Then    'If present, this record should always be last in the recordset                  
                        rs.Delete
                        rcnt = rs.RecordCount
                        rs.Close
                        GoTo lpout                  'Have to jump out in case that was last record; the MoveNext would throw an error
                    End If                                              
                    rs.MoveNext
                Next i
                
lpout:
                If rcnt = 0 Then GoTo cleanup
            End If  
                                                    
            DoCmd.OpenReport "rptMissingJobCodes", acViewPreview
            ChkJobCodes = "True"
            Exit Function 

I tried putting rs.update after the rs.delete statement. But got an error saying there was no Addition or Edit.

Any suggestions are welcomed.

Thanks,
Vic

RE: Deleted record in recordset reappears when recordset used as report datasource

(OP)
Sorry people. I think I was half asleep. The query is based on two tables. I have to remove the unwanted record from the table, not the query.

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!

Resources

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