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,888 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 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 learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Suggested Courses
Course of the Month7 days, 8 hours left to enroll

632 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