UtterAccess.com
We have detected that you are using an unsupported web browser. We recommend you to upgrade your web browser to get the most from UtterAccess forums.
Why should and how can I upgrade?
X   Site Message
(Message will auto close in 2 seconds)

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Prevent Accidental Deletion Of Data, Office 2010    
 
   
snapjuice
post Feb 28 2012, 01:45 PM
Post #1

New Member
Posts: 2



I am using the 'contacts list' template that came with Access 2010. I am new to Access.
I would like to prevent accidental deletion of existing records. How do I do this? can I lock the content of the cells like in the old "Microsoft Works"?
Thanks in advance for your help.
Go to the top of the page
 
+
rbianco
post Feb 28 2012, 01:53 PM
Post #2

UtterAccess VIP
Posts: 1,731
From: Carrollton, TX



Welcome to UA
welcome2UA.gif
The best way to prevent "accidental deletions of data" is to control your user through forms designed with restrictive properties. Add Only set to YES, and/or Allow Deletions set to NO.
You should be able to set those properties in the CONTACTS template database.
(Now this of course does not speak to deliberate deletion/sabbotage of data, in which case you want security and backups.)
Go to the top of the page
 
+
River34
post Feb 28 2012, 01:58 PM
Post #3

UtterAccess Addict
Posts: 252
From: Metro Detroit



Okay, Snapjuice. First, welcome to the world of Microsoft Access. It can be a fun place to play or it can bring you to tears. Better earmark the forums you find most helpful.
All forms, controls, etc. in Access let you lock records in various ways. First, you need to right click on the form or control and go to it's property sheet. This is where you control the data. You can enable/disable, lock/unlock, allow edits, allow deletions, record locks, etc. for all of the data. Go to the 'All' tab and see what properties will do the job for you. Let us know if you need more help. Please be more specific with your questions.
Go to the top of the page
 
+
doctor9
post Feb 28 2012, 02:11 PM
Post #4

UtterAccess Editor
Posts: 12,734
From: Wisconsin



snapjuice,
welcome2UA.gif
Are you referring to the database with the form that has a dark blue header that reads "Contact List", and includes things like "Getting Started Videos", and "Provide Feedback" and "Help" in the upper right corner of the form?
If so, here's a quick and simple way to help prevent accidental deletions.
1. Open the form in Design View
2. Open the Properties Sheet if necessary (Alt-Enter)
3. Select the Event tab on the Properties Sheet
4. Find the "Before Del Confirm" event. Click once on the white area to the right of that name.
5. A button with a "down arrow" on it, and another button with three little dots on it will appear to the right of where you clicked. Click the three-dots button.
6. Now you'll be taken to the Visual Basic Editor. The header and footer for the "Before Delete Confirm" event are created for you. Add the following code between the header and footer:
CODE
Private Sub Form_BeforeDelConfirm(Cancel As Integer, Response As Integer)
    If MsgBox("Are you sure you want to delete " & Me.First_Name & " " & _
                        Me.Last_Name & "from the Contacts list?", vbYesNo) = vbNo Then
        Cancel = True
    End If

End Sub

Now, if the user tries to delete a record while using that form, they'll get a warning message first. If they click the "Yes" button, the record will get deleted. If they click "No", the deletion will be cancelled.
Hope this helps,
Dennis
Go to the top of the page
 
+
snapjuice
post Feb 28 2012, 03:42 PM
Post #5

New Member
Posts: 2



Hi Dennis. Thanks very much. I am using the one you referred to.
added the code you gave me - it now looks like this in Design View:
Private Sub Form_BeforeDelConfirm(Cancel As Integer, Response As Integer)
If MsgBox("Are you sure you want to delete " & Me.First_Name & " " & _
Me.Last_Name & "from the Contacts list?", vbYesNo) = vbNo Then
Cancel = True
End If
End Sub
I have used backspace to remove a field. I got no 'Are you sure you want to delete....'
I saved it and got out and back into Access, still not working.
ANy other suggestions?
Thanks
Kevin
Go to the top of the page
 
+
doctor9
post Feb 28 2012, 04:49 PM
Post #6

UtterAccess Editor
Posts: 12,734
From: Wisconsin



Kevin,
h, there's a subtle difference between deleting an entire record of fields, and changing a single field value to an empty string/Null.
First, if you hit Backspace or Del and accidentally "delete" a field value, you can just hit the [Esc] key to restore the old value, as long as you do so before moving to another record.
If you want to add some VBA code to alert your users to this fact, you can try adding this sort of code to the AfterUpdate Event of each control you want to protect in this way. The following is for the "First_Name" textbox on the form:
CODE
Private Sub First_Name_BeforeUpdate(Cancel As Integer)
    
    If Len(Me.First_Name & "") = 0 Then
        If MsgBox("Are you sure you want to delete this value?", vbYesNo) = vbNo Then
            Cancel = True
            MsgBox "Please hit {ESC} to restore the old value before proceeding."
        End If
    End If
End Sub

You can basically copy/paste the code between the headers into several controls' BeforeUpdate events. Just change the value in the first line of code ("If Len(Me.CONTROLNAME & "")=0 Then") to match the control name in the subroutine header.
Hope this helps,
Dennis
Go to the top of the page
 
+

Thank you for your support! Reply to this topicStart new topic

Jump To Forum:
 



RSS Search  ·  Go to Top  ·  Lo-Fi Version Time is now: 31st October 2014 - 09:49 AM