Link to home
Start Free TrialLog in
Avatar of valmatic
valmaticFlag for United States of America

asked on

do not allow subform entry until fiels in parent are filled

Hi.  I am trying to make controls in my subform or the subform as a whole, inactive until specific controls on my main form are filled. I've tried a number of things and am having no luck.  I figured the easiest would be to use the gotfocus property of a control on my subform and if parent control is null then setfocus back to the parent control and isue a message to the user.  The logic works but as soon as I open my parent form the message I'm sending my user pops up and it doesn't matter which subform control I wrap this code around either.  I'm confused as to why my subform controls all seem active when I open the parent form.  Is there a way to keep the subform from being active until the user manually activates it?  What's the best way to keep users from entering data into a subform until they have properly filled the parent form? I am including code from my subform.
Private Sub ExpDate_GotFocus()
If IsNull(Me.Parent!TripFinish) Then
    MsgBox "Fill in the Trip Detail above before entering Expense data.", , "ERROR"
    Me.Parent!TripPurpose.SetFocus
End If
End Sub

Open in new window


parent form = frmTripDetail
parent form control = TripFinish
Subform = subfrmExpDetail
subform control = ExpDate
Key field = TripID

thanks
Avatar of Jeffrey Coachman
Jeffrey Coachman
Flag of United States of America image

To spare you the never ending debate, ...

You can validate the fields in the Before Update event of the main form.

Trying to do this "On-the-fly", while in the field is always problematic.

Private Sub Form_BeforeUpdate(Cancel As Integer)
    If isnull(me.YourField) then
        msgbox "You must fill in YourField."
        me.YourField.stefocus
    End if
    Cancel=True
End Sub

But lets see what other experts may post...

;-)


jeff
SOLUTION
Avatar of Jeffrey Coachman
Jeffrey Coachman
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
hnasr,

As always, thank you for that great additional info...
;-)

Jeff
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of valmatic

ASKER

Thanks for all of the responses on this one guys.  I tried variations of each of your posts and could not get it to work exactly like I wanted it so I'm changing tactics.  I'm going to make the controls on my subform non-maintainable so data is preview only.  User can call an entry form through a button on the main form, which will ultimately populate my subform.  User can add as many entries as he wants without actually touching my subform and hopefully minimize mistakes and bogus entries.  I think that's the theory LSM and Fyed wer trying to get across..  NO idea how to split this one so am just doing an even split for everyone.  As always, I appreciate the great input.