Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2014-09-08
4
Medium Priority
?
2,034 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 85

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 2000 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

This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
If you’re using QODBC to update QuickBooks data from Microsoft® Access but Access is not showing the updated data, you could have set up QODBC incorrectly.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
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…

927 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