Solved

do not allow subform entry until fiels in parent are filled

Posted on 2012-12-28
7
632 Views
Last Modified: 2013-01-09
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
0
Comment
Question by:valmatic
7 Comments
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 38728296
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
0
 
LVL 74

Assisted Solution

by:Jeffrey Coachman
Jeffrey Coachman earned 125 total points
ID: 38728300
Slight code corrections:

Private Sub Form_BeforeUpdate(Cancel As Integer)
    If IsNull(Me.YourField) Then
        MsgBox "You must fill in YourField."
        Me.YourField.SetFocus
        Cancel = True
    End If
End Sub
0
 
LVL 30

Assisted Solution

by:hnasr
hnasr earned 125 total points
ID: 38728628
"To spare you the never ending debate, ..."
Agree with boag2000!

Which field will trigger end of entry?
Which fields allow nulls?

One idea, to check for newrecord, and disable the subform.
At the point you are satisfied with main form entry, enable subform.

Private Sub Form_Current()
    If NewRecord Then
        subForm.Enabled = False
    Else
        subForm.Enabled = True
   End If

In a button enable subform in data entry.

    subForm.Enabled = True

This can be set as boag2000 suggested in before update event of the main form.
And as boag2000 mentioned this can go on for a while analysing the problem.
0
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 38728695
hnasr,

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

Jeff
0
 
LVL 84

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 125 total points
ID: 38728955
Another idea is to develop a routine that checks each of the mainform's controls and enables/disables the subform based on the results of that. You would then just call that routine in one of the control Events (AfterUpdate, Exit, LostFocus, etc). Something like:

Function CheckRecord as Boolean

Dim bOK As Boolean
bOK = True '/ assume everything it okay

bOK= Nz(Me.Textbox1,"") = "" 
'/ If bOK is already false, we don't reset it - we only
'/ continue the checks if the previous controls return True
If bOK Then
  bOK = Nz(Me.Textbox2, "") = ""
End If

If bOK Then
  bOK = Nz(Me.Combo1.Column(0), "") = ""
End If

Me.YourSubformControl.Enabled = bOK

End Function

Now just call CheckRecord for each control that is used to determine if the mainform record is valid. Again, use the AfterUpdate, Exit, LostFocus, etc etc to determine that.
0
 
LVL 47

Assisted Solution

by:Dale Fye (Access MVP)
Dale Fye (Access MVP) earned 125 total points
ID: 38728992
I agree with LSM.  Whenever I use a subform this way, I almost always disable the subform in the main forms Current event if Me.NewRecord = True.

I then have a Save button on the main form, which runs through my required fields and makes sure they are all filled in.  If not, it sets the focus to the missing control(s) sequentially and after all controls are filled in, the Save button will save the record and enable the subform.
0
 
LVL 7

Author Closing Comment

by:valmatic
ID: 38759225
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.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now