Can't delete records from table

D

Duck

I have a database which I actually developed on my home laptop and
then copied to my work laptop in my office. The problem is that I am
not able to delete certain rows from my customer table (which I
discovered contained duplicate data) either via a short VBA procedure
or via a delete query. However I can open the table in worksheet view
and delete rows manually.

When I use the procedure:

Public Sub RemoveDupstblCustomer()

'Declare variables
Dim rstDups As New ADODB.Recordset
Dim rstCust As New ADODB.Recordset
Dim numCustIDDups As Long
Dim numCustIDCust As Long
Dim strName As String

'Open temptblCustDups for list of duplicate records, move to first
record and assign variable values
With rstDups
.Open "temptblCustDups", CurrentProject.Connection,
adOpenDynamic, adLockBatchOptimistic
.MoveFirst
Do Until .EOF
numCustIDDups = .Fields("CustID")
strName = .Fields("WholeName")
'Open tblCustomer and move to first record and assign
variable values
With rstCust
.Open "tblCustomer", CurrentProject.Connection,
adOpenDynamic, adLockBatchOptimistic
.MoveFirst
'Set up loop and assign variables
Do Until .EOF
numCustIDCust = .Fields("CustID")
If numCustIDDups = numCustIDCust Then
.Delete
Debug.Print strName & " Deleted from
tblCustomer"
End If
.MoveNext
Loop
End With
rstCust.Close
.MoveNext
Loop
End With
rstDups.Close

End Sub

I get the proper responses out to the immediate window (<strName>
Deleted from tblCustomer) however a check of the table afterwards
reveals the same number of records.

When I use the delete query (with the query design environment) that
results in the SQL statement:

DELETE tblCustomer.*
FROM tblCustomer INNER JOIN temptblCustDups ON tblCustomer.CustID =
temptblCustDups.CustID;

I get an error message stating: "Could not delete from specified
tables"
What am I doing wrong?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top