Solved Sub datasheet not allowing new records after setting no edit in main datasheet form (1 Viewer)

Jomat

Member
Local time
Today, 03:13
Joined
Mar 22, 2023
Messages
35
Have anyone ran into this issue?
I have a form with a subform. Both are viewed in datasheet view. When I set the main datasheet form to no edit, the subfrom (viewed in datasheet view) no longer offers a new record input line. Any ideas? Thanks.
 

LarryE

Active member
Local time
Today, 03:13
Joined
Aug 18, 2021
Messages
591
That's because a subform is just another control type of the main form so if you set the mainform to not allowing edits, naturally as a control type, the subform won't allow editing or adding new records either.
 

Jomat

Member
Local time
Today, 03:13
Joined
Mar 22, 2023
Messages
35
The main form still allows new records. Just the sub form does not.
 

isladogs

MVP / VIP
Local time
Today, 11:13
Joined
Jan 14, 2017
Messages
18,225
Not sure how you have a datasheet subform showing in a datasheet form
Care to explain with screenshots in design view & form view
 

CJ_London

Super Moderator
Staff member
Local time
Today, 11:13
Joined
Feb 19, 2013
Messages
16,612
Suspect op means subdatasheet
 

Jomat

Member
Local time
Today, 03:13
Joined
Mar 22, 2023
Messages
35
I'm not at the computer now but what I did was: main form datasheet view, subform dropped onto main form. I didn't space anything. Sub form also set to display in datasheet view. Link the ids then open the main form. It looks. Like the the table with the sub table expanded.
I found a way to make it work. Since I don't want end users to edit the main form data and only add to the sub form. So I coded the main form that if the id is blank then certain fields can be edited or added. I use the on current event and set the codes to use the me.myfield.locked =true
Sorry I will add an example later when I get back to the desk. My apologies if I am not clear on the explanation above.
 

Jomat

Member
Local time
Today, 03:13
Joined
Mar 22, 2023
Messages
35
I've included a sample db. You can see what I did. The main form will be the example. Ignore all the other junk reports and etc.
Any feed back? Let me know. I did forget to lock one of the field though. Thanks for all the responses.
 

Attachments

  • Database13.accdb
    1.3 MB · Views: 66

CJ_London

Super Moderator
Staff member
Local time
Today, 11:13
Joined
Feb 19, 2013
Messages
16,612
When I set the main datasheet form to no edit, the subfrom (viewed in datasheet view) no longer offers a new record input line.
works for me - you have to complete the entire line. If you don't you can't go back to edit
image_2023-04-01_105635354.png
 

Jomat

Member
Local time
Today, 03:13
Joined
Mar 22, 2023
Messages
35
Gasman, yes edit must be set to yes. That was the original issue. If I set edit to no on the main form, then the subform won't allow new entries. I found this odd so I had to come up with another way.
 

CJ_London

Super Moderator
Staff member
Local time
Today, 11:13
Joined
Feb 19, 2013
Messages
16,612
Edit was set to Yes in the mainform though?
tried both yes and no didn't make any difference to the subform - you can still add new records. See below, you can see I am in the main form from the highlighted text
1680363054286.png


1680363151054.png


perhaps I'm not understanding the issue
 

Gasman

Enthusiastic Amateur
Local time
Today, 11:13
Joined
Sep 21, 2011
Messages
14,301
Hmm,
If I open as is, I get first pic
If I go into design and then back out, I get the second pic.?
So I expanded the control to be able to see the subform, and when I changed main form to AllowEdits = No, then I could not add the subform record, before that I could.

O/P, try locking your mainform controls, except for the subform control, if you get the same as myself?
 

Attachments

  • Pic 1.PNG
    Pic 1.PNG
    54 KB · Views: 50
  • Pic 2.PNG
    Pic 2.PNG
    25.5 KB · Views: 47

Jomat

Member
Local time
Today, 03:13
Joined
Mar 22, 2023
Messages
35
This was the original problem. If I locked the main form, (set it to no edit) then the subform does not allow new entries. I've included a sample below. I get the same results as Gasman.
 

Attachments

  • Database13.accdb
    1.3 MB · Views: 54

Josef P.

Well-known member
Local time
Today, 12:13
Joined
Feb 2, 2023
Messages
826
You can use code to set AllowAdditions/AllowEdits to true/false.

In design mode: set AllowEdits to True

Code in main form:
Code:
Private Sub Form_Load()
   Me.AllowEdits = False
   Me.FRM_MESSAGES_RESPONSE_SENDER_MASTER_RESTRICTED.Form.AllowEdits = False
End Sub

/edit:
Note: AllowAddition = True in (Form_Load) will only work for subform in 1. record.
 
Last edited:

Gasman

Enthusiastic Amateur
Local time
Today, 11:13
Joined
Sep 21, 2011
Messages
14,301
You can use code to set AllowAdditions to true.

Code in main form:
Code:
Private Sub Form_Load()
   Me.FRM_MESSAGES_RESPONSE_SENDER_MASTER_RESTRICTED.Form.AllowAdditions = True
End Sub
Could you not just use Me.Parent?
 

Jomat

Member
Local time
Today, 03:13
Joined
Mar 22, 2023
Messages
35
You can use code to set AllowAdditions to true.

Code in main form:
Code:
Private Sub Form_Load()
   Me.FRM_MESSAGES_RESPONSE_SENDER_MASTER_RESTRICTED.Form.AllowAdditions = True
End Sub
It is weird. I've tried that already. When I try to force it, only the first record in the sub form allows new entry and any thing else in the sub form does not allow new entries.
 

Josef P.

Well-known member
Local time
Today, 12:13
Joined
Feb 2, 2023
Messages
826
See attachment:
 

Attachments

  • Database13.zip
    40.7 KB · Views: 66

Gasman

Enthusiastic Amateur
Local time
Today, 11:13
Joined
Sep 21, 2011
Messages
14,301
You can use code to set AllowAdditions/AllowEdits to true/false.

In design mode: set AllowEdits to True

Code in main form:
Code:
Private Sub Form_Load()
   Me.AllowEdits = False
   Me.FRM_MESSAGES_RESPONSE_SENDER_MASTER_RESTRICTED.Form.AllowEdits = False
End Sub

/edit:
Note: AllowAddition = True in (Form_Load) will only work for subform in 1. record.
I am struggling to see the point of setting edits to no in design mode, only to unset them in form load?
Edit: ok, it seems that would allow just one record?
 

Gasman

Enthusiastic Amateur
Local time
Today, 11:13
Joined
Sep 21, 2011
Messages
14,301
It is weird. I've tried that already. When I try to force it, only the first record in the sub form allows new entry and any thing else in the sub form does not allow new entries.
That was mentioned in an edit of that post?
 

Josef P.

Well-known member
Local time
Today, 12:13
Joined
Feb 2, 2023
Messages
826
@Gasman: Posts (my change and the new post) overlapped in time, so I still added the note in #14.
First I tested:
Code:
Private Sub Form_Load()
   Me.FRM_MESSAGES_RESPONSE_SENDER_MASTER_RESTRICTED.Form.AllowAdditions = True
End Sub
this has only effect for 1. record.
 
Last edited:

Users who are viewing this thread

Top Bottom