Link to home
Start Free TrialLog in
Avatar of Tony
Tony

asked on

Delete Control + A

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,
Avatar of Dale Fye
Dale Fye
Flag of United States of America image

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


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

Avatar of Tony
Tony

ASKER

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.

?
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
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
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.
ASKER CERTIFIED SOLUTION
Avatar of Jim Dettman (EE MVE)
Jim Dettman (EE MVE)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial

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

Open in new window

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.


Avatar of Tony

ASKER

good/ thank you.