Solved Validating Data in Subform (1 Viewer)

Weekleyba

Registered User.
Local time
Today, 03:17
Joined
Oct 10, 2013
Messages
586
When opening F_Project form to a specific ProjectID, I have some code to check if 3 fields are populated. If they are populated, then all the other controls that are Enable No, change to Enable Yes. Otherwise the stay with Enable No.
This method works for all the controls that are on the F_Project.
The code is in a On Click event in another form, F_Main. When I click on a project in F_Main, it opens the F_Project where the ProjectID matches and then runs the code for Enabling the controls.
Ok, with that said, I would like to do something similar with a subform on the F_Project. The subform is on the page called Submittals, and the subform is called SubmittalF. I am forcing the user to populate the Date of Submittal field by use of the Before Update event. This works fine. But when I come back to the subform, I need the code to run Enable Yes for the controls.
If tried putting the code in the SubmittalF's OnCurrent, OnGotFocus events but it does not work.
Also tried in the to fire the code below from the page's On Click event. No dice.
(the green highlight is just to indicate that these three field are actually on another subform. It gets populated through a query)

Any ideas how I can make this happen?

1660142702910.png


Here's one of my attempts. This is attempting to fire the code below from the page's On Click event.

1660143753817.png



1660143896981.png
 

Attachments

  • 1660144127683.png
    1660144127683.png
    43.8 KB · Views: 63

theDBguy

I’m here to help
Staff member
Local time
Today, 01:17
Joined
Oct 29, 2018
Messages
21,473
Have you tried using the Tab Control's Change event?
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 09:17
Joined
Jul 9, 2003
Messages
16,282
I agree with DBguy, I think you should consider using the Tab control Change Event.

Having said that, I think there's an error in your code here:-

Code:
With Forms!F_Project.SubmittalF
Should be:-
Code:
With Forms!F_Project.SubmittalF.Form
Because your subform will be housed in a subform/subreport control. The subform/subreport control often adopts the same name as the form contained within it. Your code isn't addressing the form, your code is addressing the subform/subreport Control.


There's an example demonstrating the Tab Control on my website HERE:-

Password Protected Tab​


 

Weekleyba

Registered User.
Local time
Today, 03:17
Joined
Oct 10, 2013
Messages
586
Thanks guys. That is get me closer to final solution.
The problem now is that the code fires when I click on any tab, causing the msgbox to appear saying you don't have any data in the Date of Submittal field. I only want that to pop up when I click the Submittals tab.
Any ideas on how to make that happen?


1660148086933.png
 

theDBguy

I’m here to help
Staff member
Local time
Today, 01:17
Joined
Oct 29, 2018
Messages
21,473
Thanks guys. That is get me closer to final solution.
The problem now is that the code fires when I click on any tab, causing the msgbox to appear saying you don't have any data in the Date of Submittal field. I only want that to pop up when I click the Submittals tab.
Any ideas on how to make that happen?


View attachment 102398
I agree. Amend your code to only run if you're on the right page.
 

Weekleyba

Registered User.
Local time
Today, 03:17
Joined
Oct 10, 2013
Messages
586
This appears to work.
Is this what you were thinking?

Code:
Private Sub TabCtProjects_Change()
   'ValidationOfControl = True when certain fields are not populated
  
   If Forms!F_Project!TabCtProjects.Value = 5 Then
      
        If ValidationOfControl(Forms!F_Project.SubmittalF.Form) = False Then
        
          With Forms!F_Project.SubmittalF.Form
          
           .DateReturned.Enabled = True
           .SubmittalNum.Enabled = True
           .Subject.Enabled = True
           .SpecificationSection.Enabled = True
           .NewSubmittal.Enabled = True
           .Resubmittal.Enabled = True
           .AdditionalInfo.Enabled = True
           .ShopDrawing.Enabled = True
           .Administrative.Enabled = True
           .AsBuilts.Enabled = True
           .Sample.Enabled = True
           .ProductData.Enabled = True
           .OM.Enabled = True
           .cmdAddSubmittal.Enabled = True
           .cmdPreviousSubmittal.Enabled = True
           .cmdNextSubmittal.Enabled = True
           .SubmittalItemSF.Enabled = True
           .NoException.Enabled = True
           .ReviewedasNoted.Enabled = True
           .ReviseandResubmit.Enabled = True
           .RejectedSubmittal.Enabled = True
           .Other.Enabled = True
           .CompleteResubmittal.Enabled = True
           .AdditionalInfoToReturn.Enabled = True
           .SubmittalComments.Enabled = True
           .cmdSubmittalTransmittal.Enabled = True
          
          End With
          
        End If
        
    End If
    
End Sub
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 09:17
Joined
Jul 9, 2003
Messages
16,282
I agree. Amend your code to only run if you're on the right page.

And you can test for the correct page as shown in the video above. You can either test for the name as suggested by Gasman or you can test for the Page Index. Each tab has a unique Index, you can test for that as shown in the video... It is returned through the Tab control "Value"...
 

Users who are viewing this thread

Top Bottom