mrussell71
IS-IT--Management
This code as been giving me trouble for a number of days. I've tried different variations to no avail. What I am trying to accomplish is automate a large number of DELETE queries by creating a recordset for each query's SQL SELECT statement, delete all records from that recordset and then move on to the next set of data to be deleted. I am using Access 2002.
The code runs as expected but the data in the underlying tables is still there. It's as if the records are getting deleted but the table isn't being updated from the recordset. However, when I step thru the code, I don't see the [tt]Do While...Loop[/tt] being used, so I'm not sure if the [tt]curRST.Delete[/tt] is being called. It jumps from the [tt]Do While curRST.EOF = False[/tt] line to the [tt]curRST.Close[/tt].
Here is the code that I am using:
[tt]
Dim curConn As New ADODB.Connection
Dim curRST As ADODB.Recordset
Dim strSQL As String
Set curConn = New ADODB.Connection
With curConn
.Provider = "Microsoft.Jet.OLEDB.4.0"
.ConnectionString = "data source=" & "\\EPC\WorkingDBs\EPC_working.mdb"
.Open
End With
strSQL = "SELECT DISTINCTROW tblEPC_query.ID, tblEPC_query.MfrCode, tblEPC_query.PartNo, tblEPC_query.Label, tblFootnotes_query.Description, tblIndex_query.EPCIndex, tblIndex_query.* "
strSQL = strSQL & "FROM tblFootnotes_query INNER JOIN (tblEPC_query INNER JOIN tblIndex_query ON tblEPC_query.ID = tblIndex_query.EPCIndex) ON tblFootnotes_query.ID = tblEPC_query.FNIndex "
strSQL = strSQL & "WHERE (((tblEPC_query.MfrCode)='A1C') AND ((tblEPC_query.PartNo) Like '18%') AND ((tblEPC_query.Label) Like '%CALIPER%') AND ((tblFootnotes_query.Description) Like '%Semi-Loaded Caliper%') AND ((tblIndex_query.EPCIndex)=[tblEPC_query]![ID]));"
Set curRST = New ADODB.Recordset
Set curRST.ActiveConnection = curConn
curRST.CursorType = adOpenDynamic
curRST.LockType = adLockOptimistic
'MsgBox strSQLa
curRST.Open strSQL
Do While curRST.EOF = False
curRST.Delete
Loop
curRST.Close[/tt]
Is there anything that I am missing here??
The code runs as expected but the data in the underlying tables is still there. It's as if the records are getting deleted but the table isn't being updated from the recordset. However, when I step thru the code, I don't see the [tt]Do While...Loop[/tt] being used, so I'm not sure if the [tt]curRST.Delete[/tt] is being called. It jumps from the [tt]Do While curRST.EOF = False[/tt] line to the [tt]curRST.Close[/tt].
Here is the code that I am using:
[tt]
Dim curConn As New ADODB.Connection
Dim curRST As ADODB.Recordset
Dim strSQL As String
Set curConn = New ADODB.Connection
With curConn
.Provider = "Microsoft.Jet.OLEDB.4.0"
.ConnectionString = "data source=" & "\\EPC\WorkingDBs\EPC_working.mdb"
.Open
End With
strSQL = "SELECT DISTINCTROW tblEPC_query.ID, tblEPC_query.MfrCode, tblEPC_query.PartNo, tblEPC_query.Label, tblFootnotes_query.Description, tblIndex_query.EPCIndex, tblIndex_query.* "
strSQL = strSQL & "FROM tblFootnotes_query INNER JOIN (tblEPC_query INNER JOIN tblIndex_query ON tblEPC_query.ID = tblIndex_query.EPCIndex) ON tblFootnotes_query.ID = tblEPC_query.FNIndex "
strSQL = strSQL & "WHERE (((tblEPC_query.MfrCode)='A1C') AND ((tblEPC_query.PartNo) Like '18%') AND ((tblEPC_query.Label) Like '%CALIPER%') AND ((tblFootnotes_query.Description) Like '%Semi-Loaded Caliper%') AND ((tblIndex_query.EPCIndex)=[tblEPC_query]![ID]));"
Set curRST = New ADODB.Recordset
Set curRST.ActiveConnection = curConn
curRST.CursorType = adOpenDynamic
curRST.LockType = adLockOptimistic
'MsgBox strSQLa
curRST.Open strSQL
Do While curRST.EOF = False
curRST.Delete
Loop
curRST.Close[/tt]
Is there anything that I am missing here??