We help IT Professionals succeed at work.

Delete Control + A

Tony
Tony asked
on
Hi,

I have put some restrictions to users to delete records from a Sub-form.   However, I notice that one of them is using Control+A and then delete.

How to avoid the use of Control+A (Select all records).

Thank you,
Comment
Watch Question

Dale FyeOwner, Dev-Soln LLC
Most Valuable Expert 2014
Top Expert 2010

Commented:

you can change the Allow Delete property of the form to "No"


This is on the Data tab of the form property dialog.

Author

Commented:
Hi Mr. Dale Fye,

How can I change the Allow Delete using VBA code.   I want some users to delete, some don't.   So it is conditional.

Thanks in advance.

?
Jeffrey CoachmanMIS Liason
Most Valuable Expert 2012

Commented:
How to avoid the use of Control+A (Select all records).
You can create an AutoKeys Macro with a submacro that executes when Control+A is pressed.,.....This macro will have no Actions,
So nothing will happen if a user presses Control+A
Since the AutoKeys Macro overrides any existing keyboard shortcuts, ...it effectively will disable users from Pressing Control+A to select all records.
You would put this macro on the front end DB for any user you "Do Not" want to use Control+A to select all records.

Sample db is attached.

Jeff Coachman
Database72.accdb
John TsioumprisSoftware & Systems Engineer

Commented:
Following on Dave's advise since you have some users that have permission to delete and some not just on the Open Event
Me.AllowDeletions = ValidUser

Open in new window

where validUser should be a function that returns Boolean = true when Valid else False
Mark EdwardsChief Technology Officer

Commented:
One of the main differences between a form's Open and Load events is the ability to make changes to the form's properties with VBA on the Open event.  Some properties can't be changed with any other event, not even the Load event.

Another example of properties that you can change on the Open event are a control's .ControlSource property, so you can dynamically set them based on the fields in the recordsource.

John's answer should do it for you.
President / Owner
Most Valuable Expert 2017
Most Valuable Expert 2012
Commented:

<< How to avoid the use of Control+A (Select all records).>>


 Along the lines of the AutoKeys marco, which is application wide, you can disable it just for this form by:


1. Turning on the Form's KeyPreview property.


2. They in the keydown event, you can do:


   If KeyCode - vbKeyA And Shift = acCtrlMask Then

       KeyCode = 0

   End If


 This will "eat up" Ctrl/A and disable it from being used.


Jim.


Dale FyeOwner, Dev-Soln LLC
Most Valuable Expert 2014
Top Expert 2010

Commented:

Tony,


I generally use something like the current event, or the form Open event to determine whether the current user has delete permissions, then I do like John suggested above

Private Sub Form_Open(Cancel as integer)
    me.AllowDeletions = bUserHasDeletePermissions
End sub

the real issue becomes determining who should have delete permissions and who shouldn't.  Is this an application wide property that you can set when your application loads, or do you need to do this individually by form?  If by form, then it is probably role based, so you would need to map individuals to roles and use those roles to determine who has those permissions.


Author

Commented:
good/ thank you.