docmd.runcommand?

  • Thread starter Thread starter Terry
  • Start date Start date
T

Terry

Why does the docmd.runcommand acccmdDeleteRecord work if it's not deleting
the last record on a continuous form but on the last record it fails with a
warning that DeleteRecord is not available, No current record?
 
Hi Terry:

Is the continuous form filtered? It may be trying to access the last record
that wasn't being displayed. I've never used this method, since there are
better ways to skin this cat:

1) Try-
Dim rst as recordset
Set rst = Forms![YourFocusForm].RecordsetClone
rst.movefirst
rst.movelast
rst.Delete
rst.Close

2) Or try (example copied from one of my databases)-
Set dbs = CurrentDb
' use the same SQL statement as that of your form
SQLStmt = "SELECT AnswerChemo.* FROM AnswerChemo ORDER BY
AnswerChemo.ACCT DESC , AnswerChemo.CDATE DESC;"
Set rst = dbs.OpenRecordset(SQLStmt)
With rst
.MoveFirst
.MoveLast
If .EOF Then
.Delete
End If
.Close
dbs.Close
End With

Regards,
Al
 
Thanks, solution 1 worked just fine.

I was having a problem with a continuous subform that has some of the
records in a details table. Just didn't think about a filter causing this
type of problem.


Al Borges said:
Hi Terry:

Is the continuous form filtered? It may be trying to access the last record
that wasn't being displayed. I've never used this method, since there are
better ways to skin this cat:

1) Try-
Dim rst as recordset
Set rst = Forms![YourFocusForm].RecordsetClone
rst.movefirst
rst.movelast
rst.Delete
rst.Close

2) Or try (example copied from one of my databases)-
Set dbs = CurrentDb
' use the same SQL statement as that of your form
SQLStmt = "SELECT AnswerChemo.* FROM AnswerChemo ORDER BY
AnswerChemo.ACCT DESC , AnswerChemo.CDATE DESC;"
Set rst = dbs.OpenRecordset(SQLStmt)
With rst
.MoveFirst
.MoveLast
If .EOF Then
.Delete
End If
.Close
dbs.Close
End With

Regards,
Al

Terry said:
Why does the docmd.runcommand acccmdDeleteRecord work if it's not deleting
the last record on a continuous form but on the last record it fails
with
a
warning that DeleteRecord is not available, No current record?
 
Back
Top