Solved Lock Subform

Emma35

Registered User.
Local time
Yesterday, 18:49
Joined
Sep 18, 2012
Messages
490
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
 
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
 
Wouldn't it be the subform control that needs to be locked?
 
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.
 
Thanks for the suggestions guys.
Ranman.....where do i put this code to get it to work ?
 
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 ?
 
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

Back
Top Bottom