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,729 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

786 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