deleting but not editing records (1 Viewer)

D

Dave the Man

Guest
I have created a form but want it so that after records have been entered into the database, they can't be edited. However, I want to be able to delete whole records by click a button on the form. In the form properties you can select if you want to allow editing, and deleting. But if editing is marked as 'no' and deleting as 'yes' it does not let you do it. I think it takes deleting as an edit, which technically it is.

Anyone know how I can do this? Version is Access XP. Cheers.
 

___

¯¯¯¯¯
Local time
Today, 14:01
Joined
Nov 27, 2003
Messages
595
Code:
    Me.AllowEdits = True
    DoCmd.RunCommand acCmdDeleteRecord
    Me.AllowEdits = False

HTH
 

___

¯¯¯¯¯
Local time
Today, 14:01
Joined
Nov 27, 2003
Messages
595
Or...
Code:
       If MsgBox("Are you sure you want to delete the selected record?", vbYesNo, "Delete?") = vbYes Then

            Me.AllowEdits = True
            DoCmd.RunCommand acCmdDeleteRecord
            Me.AllowEdits = False
       Else
       
       End If

HTH
 
D

Dave the Man

Guest
It does sort of help thanks, but there's a glitch. When you click on 'delete' and then 'no' it brings up a runtime error '2501'. I want it to just go back to the form here. Any ideas?
 

___

¯¯¯¯¯
Local time
Today, 14:01
Joined
Nov 27, 2003
Messages
595
Code:
       If MsgBox("Are you sure you want to delete the selected record?", vbYesNo, "Delete?") = vbYes Then

            Me.AllowEdits = True
            DoCmd.RunCommand acCmdDeleteRecord
            Me.AllowEdits = False
       Else
            DoCmd.CancelEvent
       End If

HTH
 
D

Dave the Man

Guest
Thanks, it's getting there, but still a couple of problems. If you click on 'delete' and then 'yes', it brings up it's own message box warning as well. I only need one message box. How can I alter this so that I just have the one that I create or the standard one?

Also, if I click on 'delete' then 'yes' then 'no' it brings up the runtime 2501 error again.

The code atm is:

Private Sub delete_record_Click()

If MsgBox("Are you sure you want to delete the selected record?", vbYesNo, "Delete?") = vbYes Then

Me.AllowEdits = True
DoCmd.RunCommand acCmdDeleteRecord
Me.AllowEdits = False
Else
DoCmd.CancelEvent
End If

On Error GoTo Err_delete_record_Click

DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70

Exit_delete_record_Click:
Exit Sub

Err_delete_record_Click:
MsgBox Err.Description
Resume Exit_delete_record_Click

Me.AllowEdits = False
End Sub
 

IMO

Now Known as ___
Local time
Today, 14:01
Joined
Sep 11, 2002
Messages
723
The code should look like this...
Code:
Private Sub delete_record_Click() 
On Error GoTo Err_delete_record_Click 

If MsgBox("Are you sure you want to delete the selected record?", vbYesNo, "Delete?") = vbYes Then 

Me.AllowEdits = True 
DoCmd.RunCommand acCmdDeleteRecord 
Me.AllowEdits = False 
Else 
DoCmd.CancelEvent 
End If 

Exit_delete_record_Click: 
Exit Sub 

Err_delete_record_Click: 
MsgBox Err.Description 
Resume Exit_delete_record_Click 

End Sub
HTH

IMO (Now known as ___)
 

Users who are viewing this thread

Top Bottom