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

Recordset delete problem 1

Status
Not open for further replies.

VickyC

Technical User
Sep 25, 2010
206
CA
hello - I have code that should delete records based on matching one table field (BinID) with a combobox (Me!cboBin.Column(0)) AND matching another field (MemID) with a listbox selection(Me!lstMem.Column(0, varItem)). My problem is the records are never deleted. The '.delete' code line is always skipped when I step through code.

Code:
'if BinID AND MemID aleady in tblBinMem, then delete it
Set db = CurrentDb()
Set rs = db.OpenRecordset("tblBinMem", dbOpenDynaset)

For Each varItem In Me!lstMem.ItemsSelected
  With rs
      Do While Not .EOF
                    
         Debug.Print !BinID; !MemID, Me!cboBin.Column(0); Me!lstMem.Column(0, varItem)

         If !BinID = Me!cboBin.Column(0) And !MemID = Me!lstMem.Column(0, varItem) Then
            .Delete
            Exit Do
         End If
                        
         .MoveNext
      Loop
                
      .MoveFirst
                                
  End With
Next varItem

Typical data from the 'debug' line is shown below. I expected deletions to occur in the 2nd line and the 10th line, but no deletions occur. What am I missing?

3 8 43
4 3 43
4 4 43
4 5 43
NullNull 43
4 1 43
3 8 45
4 3 45
4 4 45
4 5 45
NullNull 45
4 1 45

Thanks for taking the time to help
Vicky
 
What about this ?
If !BinID = Val(Me!cboBin.Column(0)) And !MemID = Val(Me!lstMem.Column(0, varItem)) Then

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks PHV - that nailed it! I'd have to admit, though, that I don't understand why the Val function is needed. Afterall, both Me!cboBin.Column(0) and Me!lstMem.Column(0, varItem) refer to Long Integers, whereas Val has a string argument. Still, it works great.

If I can ask for my own education, would it have been better to use SQL to do these deletions? I don't have a strong feel for when SQL solutions are preferable to DAO ones.

Much thanks for your assistance
Vicky

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top