Delete button is not the same as RunCmd delete?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Hello, everybody,

I ran into a very strange behaviour of Access 2000 and 2003 that I can't explain. Any ideas would be very helpful. Here is what I have:

- A table "tblFiles" with an "autonum" field "filNr" and a Text(30) field "filName".

- The table has a primary index and an unique, nonulls index on "filName".

- There is a query "qryFilesOrderedByName" which reads "select * from tblFiles order by filName;".

- I have a form that has "qryFilesOrderedByName" as it's data source.

- On that form is an unbound combo box which has a data source of "qryFilesOrderedByName".

- There is also a button "btnDel" that should delete the current record.

- The code of the form reads like this:

[code]
Option Compare Binary
Option Explicit

Private Sub btnDel_Click()
On Error GoTo Err_btnLöschen_Click

DoCmd.SetWarnings False
DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdDeleteRecord
DoCmd.SetWarnings True

Exit_btnDel_Click:
Exit Sub

Err_btnDel_Click:
MsgBox Err.Description
Resume Exit_btnLöschen_Click

End Sub

Private Sub cboFile_NotInList(NewData As String, Response As Integer)
Dim db As DAO.Database
Dim rs As DAO.Recordset

Set db = CurrentDb
Set rs = db.OpenRecordset("tblDateien")

'
' Add the new file to the table
'
rs.AddNew
rs!datName = NewData
rs.Update

rs.Close
Set rs = Nothing
Response = acDataErrAdded
End Sub

Private Sub Form_Current()
cboFile.Value = Me!filNr
End Sub

Private Sub Form_Delete(Cancel As Integer)
Dim i As Long

i = MsgBox("This delete is canceled!", vbExclamation + vbOKOnly, Delete canceled")

Cancel = True
End Sub
[/code]

What this effectively does is, that it shows the values of "tblFiles" and allows to add additional file names. Now for the strange thing:

If I press the "Del" button I get an error message that "action RunCmd was cancelled". If I try to delete the record (which doesn't work since it is cancelled) by pressing the "delete record" button on the toolbar I don't get this error message.

This is a very stripped down example. The true application does a lot more when it decides wether the delete should be cancelled or not, but it has the strange effect that I get a "no current record" error message when I cancel by pushing the "Del" button and no error message when I press the "delete record" button on the toolbar.

What is happening here? Any ideas how to remedy this? Any help would be greatly appreciated. Sorry for posting so much text.


Regards,

Frank
.



Relevant Pages

  • Re: Delete button is not the same as RunCmd delete?
    ... Private Sub cboFile_NotInList ... Dim rs As DAO.Recordset ... If I press the "Del" button I get an error message that "action RunCmd ... I cancel by pushing the "Del" button and no error message when I press the ...
    (microsoft.public.access.formscoding)
  • Re: Module Not Found
    ... Repeat until the code compiles okay. ... Private Sub cmdCancel_Click ... The error message could be related to something else that is going on, ... VB and press the cancel button I receive the error message "Module ...
    (microsoft.public.access.formscoding)
  • Re: Module Not Found
    ... Private Sub cmdCancel_Click ... DoCmd.Close acForm, Me.frmReroutes_Report_By_Contact ... The error message could be related to something else that is going on, ... VB and press the cancel button I receive the error message "Module Not ...
    (microsoft.public.access.formscoding)
  • Re: Conditional Field, Need Code
    ... I get an error message: ... Private Sub Form_BeforeUpdate ... Cancel ... "Rick B" wrote: ...
    (microsoft.public.access.forms)
  • Re: trapping users leaving new record b4 entring reqd data
    ... that out when i got your vba. ... Private Sub Form_BeforeUpdate ... Dim strMsg As String ... Cancel = True ...
    (microsoft.public.access.modulesdaovba)