Solved Lock Subform (1 Viewer)

Emma35

Registered User.
Local time
Yesterday, 20:25
Joined
Sep 18, 2012
Messages
467
Hi All,
I've Googled this to death and found one or two solution suggestions but they don't work for me.
If i have a parent form called frm_Main and a SubForm called frmDetails, is it possible to keep frmDetails locked until the four fields on the parent form are filled in ?. By locked i mean you cannot enter any information into the sub form at all until FieldA, FieldB, FieldC and FieldD on the parent form are populated.

Thanks guys
Em
 

Ranman256

Well-known member
Local time
Yesterday, 23:25
Joined
Apr 9, 2015
Messages
4,337
set the subform default property .LOCKED =true
then when user alters a box, do the check to unlock.

It also checks when you load the record.


Code:
Function IsValidMasterFrm() as boolean
IsValidMasterFrm = not isnull(FIELDa) and not isnull(FIELDb) and  not isnull(FIELDc) and  not isnull(FIELDd) 
end function

sub Form_Current()
 EnableSubFrm
end sub


sub EnableSubFrm()
 me.FrmDetails.Locked = not IsValidMasterFrm()
end sub

sub FIELDa_Afterupdate()
EnableSubFrm
end sub

sub FIELDb_Afterupdate()
EnableSubFrm
end sub

sub FIELDc_Afterupdate()
EnableSubFrm
end sub

sub FIELDd_Afterupdate()
EnableSubFrm
end sub
 

Gasman

Enthusiastic Amateur
Local time
Today, 04:25
Joined
Sep 21, 2011
Messages
14,310
Wouldn't it be the subform control that needs to be locked?
 

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 23:25
Joined
Feb 19, 2002
Messages
43,293
No need to lock anything. In the subform's BeforeInsert event, make sure the parent form has an autonumber. This prevents the subform from attempting to create a record when there is no parent record.

Then you need validation in the parent form's BeforeUpdate event to prevent the record from being saved if the four fields have not been entered as well as any other validation. This prevents the focus from leaving the parent form until the record has been cleared or saved without errors.
 

Emma35

Registered User.
Local time
Yesterday, 20:25
Joined
Sep 18, 2012
Messages
467
Thanks for the suggestions guys.
Ranman.....where do i put this code to get it to work ?
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 11:25
Joined
May 7, 2009
Messages
19,245
see the code on the Mainform and the subform.
 

Attachments

  • NeedToFill4Fields.accdb
    532 KB · Views: 72

Emma35

Registered User.
Local time
Yesterday, 20:25
Joined
Sep 18, 2012
Messages
467
It seems to be working fine arnel thank you. I have one question.....if i don't enter any information into the parent form and go straight to the subform, it will accept information and then let me save it. Can this be prevented ?
 

Emma35

Registered User.
Local time
Yesterday, 20:25
Joined
Sep 18, 2012
Messages
467
Sorry arnel my mistake. I forgot to add the little bit of code to the BeforeInsert event of the subform.
Working fine and thanks a lot for your help

Em x
 

Users who are viewing this thread

Top Bottom