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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Deleted record in recordset reappears when recordset used as report datasource

Status
Not open for further replies.

VicM

Programmer
Sep 24, 2001
443
US
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    [COLOR=#4E9A06]'If present, this record should always be last in the recordset[/color]                  
                        rs.Delete
                        rcnt = rs.RecordCount
                        rs.Close
                        GoTo lpout                  [COLOR=#4E9A06]'Have to jump out in case that was last record; the MoveNext would throw an error[/color]
                    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
 
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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top