Datasheet as subform, turn Add, Delete, Edit ON/OFF (1 Viewer)

dougcouch

Registered User.
Local time
Today, 07:10
Joined
Apr 14, 2014
Messages
12
I created a form with a Datasheet as subform, and need to turn Add, Delete, Edit ON/OFF. I've tried various VBA methods, such as setting these 3 properties for the main form True/False via a command button. This sets the main form, but does not prevent anything on the subform. Search yielded one post (50638) on this topic; however, trials did not end with success.

Additionally, I set the .Locked property of the subform to False/True along with the above 3 properties in the main form...all to no avail.


  • (Misc Note: "This Main form" is opened from a "larger main form" via command button.)
  • This Main form is based on table: tblDOCUMENTSonly
  • This Main form has 3 controls:
    • Close command button
    • ON/OFF command button (toggle, toggle config works fine in other forms where appropriate)
    • Datasheet as subform
  • Subform is based on table: tblDOCUMENTSonly (default view: Datasheet)
    • 2 Fields (in table): DocumentInMainFolder, MainFolder
    • DocumentInMainFolder is indexed no duplicates in this table
    • MainFolder is indexed duplicates OK in this table
      • MainFolder is indexed no duplicates in table tblMainFolderONLY
        • Relationship 1toMany (docs in docs table=1, folders in docs table=many)
        • tblMainFolderONLY has 2 fields: MainFolder (no dupl), DocumentCategory (dupl OK, field not involved in these forms)
    • Although the database has a total of 9-ea. 1toMany relationships, there is only one relationship involving tblDOCUMENTSonly (to tblMainFolderONLY)
A simple form configuration, but I'm having difficulty turning any and all types of editing ON/OFF (with OFF defaults). Just an area I've never dealt with before the last week or so. I do not need to necessarily fix my existing methods, unless that's the best way. I can attempt to implement most anything suggested in a copy of the database, etc. The database is a personal one, rather than for work or any client (I wisely don't have any LOL).
 

CJ_London

Super Moderator
Staff member
Local time
Today, 14:10
Joined
Feb 19, 2013
Messages
16,555
if the subform is only used in the one main form, then just set those properties in the subform design.

If you want to use code, the code is

me.subformctrlname.from.allowadditoons=false

note this is the name of the subform control not the form which is it's sourceobject
 

dougcouch

Registered User.
Local time
Today, 07:10
Joined
Apr 14, 2014
Messages
12
I'll take a closer look and test using that code. In this case, Name and Source Object are the same, which is also the name of the form file itself. I didn't mention earlier, but no Child/Master Links have been setup.
 

CJ_London

Super Moderator
Staff member
Local time
Today, 14:10
Joined
Feb 19, 2013
Messages
16,555
couple of small typos in my code - it should be

me.subformctrlname.form.allowadditions=false

You will normally need set the child and master links if there is a child/masterrelationship with your main form, otherwise, leave blank
 

dougcouch

Registered User.
Local time
Today, 07:10
Joined
Apr 14, 2014
Messages
12
Thanks for the heads up. Just got back home from an early morning trip. Won't be checking into it until later.
 

dougcouch

Registered User.
Local time
Today, 07:10
Joined
Apr 14, 2014
Messages
12
Finally made it back to test the code. It worked great (without any lock/unlock needed). My problem was that I was leaving out ".Form" in my syntax. THANKS!
 

Users who are viewing this thread

Top Bottom