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

Jomat

Member
Local time
Today, 01:45
Joined
Mar 22, 2023
Messages
35
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?
The form is to allow new entries only and no deletions or edits.
Sorry my msgs are overlapping.
Thanks guys for all your inputs.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 04:45
Joined
Feb 19, 2002
Messages
43,275
If I set edit to no on the main form, then the subform won't allow new entries.
The subdatasheet is NOT a subform. It is using the properties of the parent form. If you want a subform, you need a real one. A way to have Two lists is to use two list view subforms on an unbound main form. The "left" subform is the main list. When you click on an item in the main form, the code in the click event requeries the "right" subform. The "right" subform is bound to a query that references the "left" subform.

Select ...
From ...
Where MyFK = Forms!mainform!subform1.Form!PKfield

Use intellisense in the QBE to get the syntax right.
 

Gasman

Enthusiastic Amateur
Local time
Today, 09:45
Joined
Sep 21, 2011
Messages
14,301
@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.
Yes, O/P discovered that. :)
Curious as to how it worked for @CJ_London
 

Josef P.

Well-known member
Local time
Today, 10:45
Joined
Feb 2, 2023
Messages
826
The subdatasheet is NOT a subform. It is using the properties of the parent form. If you want a subform, you need a real one.
In the example, a subform was explicitly set by the OP for this purpose.
What else but a subform should the subform control be in this example?
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 04:45
Joined
Feb 19, 2002
Messages
43,275
What else but a subform should the subform control be in this example?
I thought he said he was using a subdatasheet
 

Josef P.

Well-known member
Local time
Today, 10:45
Joined
Feb 2, 2023
Messages
826
The OP uses a form with datasheet view in the subform control.
Curiously, the change to AllowAdditions=True in the UF only works for the 1st record in the main form. AllowEdits works for all displayed subform masks.

/edit:
However, this is only the case in the datasheet view. If you use the subform as a continuous form, AllowAdditions works for all of them.

Code:
Private Sub Form_Load()
   With Me.FRM_MESSAGES_RESPONSE_SENDER_MASTER_RESTRICTED.Form
      .AllowAdditions = True
   End With
End Sub
... this works only with continuous form, not with datasheet view.
If you press {F5} in the subform (without new record line) new records also allowed in the other records of main form.
 
Last edited:

Pat Hartman

Super Moderator
Staff member
Local time
Today, 04:45
Joined
Feb 19, 2002
Messages
43,275
Have you tried setting the AllowAdditions property in the form or subform's Current event so that it runs for EACH record instead of just once when the form loads?
 

CJ_London

Super Moderator
Staff member
Local time
Today, 09:45
Joined
Feb 19, 2013
Messages
16,612
Curious as to how it worked for @CJ_London
No idea, but since I couldn't replicate the issue, I didn't feel I could contribute anything meaningful
 

Gasman

Enthusiastic Amateur
Local time
Today, 09:45
Joined
Sep 21, 2011
Messages
14,301
The form is to allow new entries only and no deletions or edits.
Sorry my msgs are overlapping.
Thanks guys for all your inputs.
Do set the form to Data Entry = yes?
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 04:45
Joined
Feb 19, 2002
Messages
43,275
This thread is marked as solved but there is no comment regarding what the solution was. Can someone update it please.
 

Josef P.

Well-known member
Local time
Today, 10:45
Joined
Feb 2, 2023
Messages
826
#14 worked in my test:
design mode: AllowEdits = true,
change to AllowEdits = false via VBA
 

Jomat

Member
Local time
Today, 01:45
Joined
Mar 22, 2023
Messages
35
This thread is marked as solved but there is no comment regarding what the solution was. Can someone update it please.
I manually coded to lock the fields based on the id field. If it's a new record with no ID number then it enables the fields for inputs. I posted a sample db as well.
 

Gasman

Enthusiastic Amateur
Local time
Today, 09:45
Joined
Sep 21, 2011
Messages
14,301
Could just use Me.NewRecord?
 

Users who are viewing this thread

Top Bottom