Solved

Passcode to delete a record

Posted on 2014-02-05
3
288 Views
Last Modified: 2014-02-05
Is there a way have to enter a password in order to delete a record? This password doesn't have to be secure at all (just more of a process). I have using the below code for a password to change an item on this form. If they were to delete the entire record, can I have it ask for the same password (which is the booking number - 111*2)?

Thanks!

Private Sub ItemPrice_BeforeUpdate(Cancel As Integer)
Dim strCorrectPassword As String

strCorrectPassword = Abs(Me.BookNumber - 1111) * 2

If Forms![MainForm]![Bookings subform].Form![DateRecorded] < Date - 1 Then    'Reads in a date field on your from called "Some Date"
    If InputBox("Enter Password") <> strCorrectPassword Then 'Compares passwords
        Cancel = True
        MsgBox "Change not allowed without valid password.", vbOKOnly
        Me.ItemPrice.Undo 'undo recent change to this field
        Exit Sub
    End If
End If
End Sub
0
Comment
Question by:cansevin
3 Comments
 
LVL 75

Expert Comment

by:DatabaseMX (Joe Anderson - Access MVP)
Comment Utility
For starters, seems you would want this code in the Form's Before Del Confirm event - which can also  be cancelled.

mx
0
 
LVL 10

Accepted Solution

by:
Gozreh earned 500 total points
Comment Utility
Private Sub Form_Delete(Cancel As Integer)
   Dim strCorrectPassword As String
   strCorrectPassword = Abs(Me.BookNumber - 1111) * 2
   If Forms![MainForm]![Bookings subform].Form![DateRecorded] < Date - 1 Then    'Reads in a date field on your from called "Some Date"
       If InputBox("Enter Password") <> strCorrectPassword Then 'Compares passwords
           Cancel = True
           MsgBox "can not delete without valid password.", vbOKOnly
           Exit Sub
       End If
   End If
End Sub

Open in new window

0
 

Author Closing Comment

by:cansevin
Comment Utility
Thanks!!!
0

Featured Post

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

772 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

10 Experts available now in Live!

Get 1:1 Help Now