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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

757 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now