Hiding a Subform when there is no data

ARW17

Board Regular
Joined
Oct 31, 2016
Messages
109
I have a form that shows employees how many vacation and personal days they have for the year.

Then there are 5 subforms that show Vacation Days Used, Vacation Days Scheduled, Denied Vacation Days, Personal Days Used, and Personal Days Scheduled.

If the employee has no Denied Vacation Days, I'd like to hide that subform. The subform is a datasheet view and contains columns for date and number (0.5 for half day or 1 for full day).

Is there a way that when the employee opens this form, if they have no denied vacation they don't see that subform at all?

Thanks!

Never mind! I found the answer:
[FONT=&quot]The following example illustrates how to hide a subform named [/FONT]Orders_Subform[FONT=&quot] if its main form does not contain any records. The code resides in the main form's [/FONT]Current[FONT=&quot] event procedure.[/FONT]

[FONT=&quot]VBA
[/FONT]

[FONT=&quot]

Private Sub Form_Current()

With Me![Orders_Subform].Form

' Check the RecordCount of the Subform.
If .RecordsetClone.RecordCount = 0 Then

' Hide the subform.
.Visible = False

End If
End With
End Sub


[/FONT]
 
Last edited:

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.

Forum statistics

Threads
1,214,788
Messages
6,121,580
Members
449,039
Latest member
Arbind kumar

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top