ExcelChampion
Well-known Member
- Joined
- Aug 12, 2005
- Messages
- 976
I cannot figure out what is wrong with this code. I get the error, "Object variable or With block variable not set."
I just don't see the problem...
Thanks for taking a look.
Todd
I just don't see the problem...
Code:
Sub remDuplicates()
Dim sSql As String
Dim RFQ_NUM As String
Dim REVISION As String
Dim DOC_LINK As String
Dim DATE_ISSUED As String
Dim lRows As Long
Dim con As ADODB.Connection
Dim rs As ADODB.Recordset
sSql = "Select RFQ_NUM, REVISION, DOC_LINK, DATE_ISSUED " _
& "From tbl_Docs " _
& "Group By RFQ_NUM, REVISION, DOC_LINK, DATE_ISSUED " _
& "Having Count(*) > 1"
Set rs = New ADODB.Recordset
With rs
.ActiveConnection = CurrentProject.AccessConnection
.CursorLocation = adUseClient
.CursorType = adOpenForwardOnly
.LockType = adLockReadOnly
.Source = sSql
.Open
While Not .EOF
sRFQ_NUM = .Fields(0).Value
sREVISION = .Fields(1).Value
sDOC_LINK = .Fields(2).Value
sDATE_ISSUED = .Fields(3).Value
sSql = "Delete* " _
& "From tbl_Docs " _
& "Where RFQ_NUM = '" & sRFQ_NUM & "' " _
& "And REVISION = '" & sREVISION & "' " _
& "And DOC_LINK = '" & sDOC_LINK & "' " _
& "And " & sDATE_ISSUED & "<> " _
& "(Select Min(" & sDATE_ISSUED & ") " _
& "From tbl_Docs " _
& "Where RFQ_NUM = '" & sRFQ_NUM & "' " _
& "And REVISION = '" & sREVISION & "' " _
& "And DOC_LINK = '" & sDOC_LINK & "')"
con.Execute sSql, lRows
.MoveNext
Wend
End With
rs.Close
Set rs = Nothing
Set con = Nothing
End Sub
Thanks for taking a look.
Todd