Solved

how to prevent user to delete a specific record on a continuous form in microsoft access 2013

Posted on 2014-09-08
4
1,760 Views
Last Modified: 2014-09-09
i use this code to try prevent user from delete a record that is locked but it's doesn't prevent to delete, what is wrong with this code?

this is my code:
Private Sub Form_BeforeDelConfirm(Cancel As Integer, Response As Integer)
If Me.Locked = True Then
    MsgBox "not able to delete a closed record"
    Cancel = True
End If
End Sub

Open in new window

0
Comment
Question by:bill201
  • 2
4 Comments
 
LVL 4

Expert Comment

by:Nuno Rogado
ID: 40310395
Hi,

Change to:
Private Sub Form_BeforeDelConfirm(Cancel As Integer, Response As Integer)
If Me.Locked Then
    MsgBox "not able to delete a closed record"
    Cancel = True
End If
End Sub
0
 

Author Comment

by:bill201
ID: 40310425
thanks
but it's not solved the problem
0
 
LVL 84

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 500 total points
ID: 40310428
Do you have the Confirm Record Changes box cleared for the database? If so, then this won't occur. From http://msdn.microsoft.com/en-us/library/bb256700(v=office.12).aspx:

The BeforeDelConfirm event does not occur and the Delete Confirm dialog box isn't displayed if you clear the Record Changes check box under Confirm on the Editing tab of the Access Options dialog box.

If you do have that box checked, then do you get the Msgbox?

You might consider using the Delete event, instead of BeforeDelConfirm. The Delete event occurs before the record is deleted, and the Record Changes box has no impact on it - it'll run regardless.

Of course another way to do this is to set AllowDeletions = False when the user enters that record. Assuming you have a field in the table that defines whether the user can delete (I'll refer to it as fDelete), you could do this in the Current event of the form:

Me.AllowDeletion = Not Me.fDelete

So if the value of Me.fDelete = True, the form would not allow that record to be deleted.
0
 

Author Comment

by:bill201
ID: 40312097
thanks alot
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question