Solved How to prevent the deletion of columns in subform by users? (1 Viewer)

yunhsuan

Member
Local time
Tomorrow, 06:58
Joined
Sep 10, 2021
Messages
54
Hello!

The column in subform can be easily deleted by selecting the whole column and click "delete" key in Datasheet view. This means users may delete colunms in subform accidentally. How to prevent this from happening?

Thanks in advance!
 

oleronesoftwares

Passionate Learner
Local time
Today, 15:58
Joined
Sep 22, 2014
Messages
1,159
Open the subform in design mode, click on the properties, look for allow deletion, pick No
 

theDBguy

I’m here to help
Staff member
Local time
Today, 15:58
Joined
Oct 29, 2018
Messages
21,487
Hello!

The column in subform can be easily deleted by selecting the whole column and click "delete" key in Datasheet view. This means users may delete colunms in subform accidentally. How to prevent this from happening?

Thanks in advance!
Users won't be able to do that if you give them an ACCDE version of the db.
 

strive4peace

AWF VIP
Local time
Today, 17:58
Joined
Apr 3, 2020
Messages
1,002
hi @yunhsuan, another consideration is that they can't do it for anyone but themself (maybe they don't want to see it) if the database is SPLIT into front-end and back-end, as it should be for multiple users ...

If they mess up their front-end and want the column back again, you could just give the front-end to them again

If there are columns you don't want them changing or removing, you can lock them (user can select but not change) and/or disable them so they show but the user can't even select it.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 18:58
Joined
Feb 19, 2002
Messages
43,331
If you do proper validation in the form's BeforeUpdate event, you can prevent a record from being updated/added if it violates your validation rules.

So, if the field is required, you should do two things.
1. Set it to be required on the table and if the field is text, set its AllowZeroLengthStrings property to No
2. Add validation in the FORM's BeforeUpdate event to ensure that it is not null so you can give the user a friendly error message.


Code:
If Me.SomeField & "" = "" Then
    Msgbox "SomeField is Required.", VBOKOnly
    Cancel = True
    Me.SomeField.SetFocus
    Exit Sub
End If
 

oleronesoftwares

Passionate Learner
Local time
Today, 15:58
Joined
Sep 22, 2014
Messages
1,159
On page load event of the form add this code
Code:
With frm
 .AllowAdditions = False
 .AllowDeletions = False
 .AllowEdits = False
 End With
 

strive4peace

AWF VIP
Local time
Today, 17:58
Joined
Apr 3, 2020
Messages
1,002
@yunhsuan, glad that works for you. The database should still be split into front-end and back-end so each user isn't sharing a copy of the front-end. Perhaps you're doing that already, but I got the idea that you're not ...
 

CJ_London

Super Moderator
Staff member
Local time
Today, 23:58
Joined
Feb 19, 2013
Messages
16,627
Open the subform in design mode, click on the properties, look for allow deletion, pick No
That only prevents users from deleting records

@yunhsuan Other option is to use a continuous form rather than a datasheet
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 18:58
Joined
Feb 19, 2002
Messages
43,331
Using .accde does not prevent user from removing values from a field. accde does prevent all design options and many that are technically not design options but are controlled by control menus. You STILL need proper validation code.
 

Users who are viewing this thread

Top Bottom