0

I have a form with a Tab control. In each tab is a subform linked to a master field on the main form. I'd like to set the tab to only be visible if the datasheet it contains has values.

For Example, the main form Master Field is a box number, If that box contains errors in it, it will populate on one of the three subforms in the tab control.

Rather than having to check each tab, I'd like it to only be visible if there is a corresponding error listed.

TabControl

Erik A
  • 31,639
  • 12
  • 42
  • 67
  • 1
    Welcome to SO! If you [edit] your post to describe where and how you're stumped with your implementation, we can probably help you. Giving us your specs without showing us how you're attempting to solve that problem can come across as asking programmers to... well, essentially work for free / do your job / homework for you... which isn't as helpful to other readers as a question about a specific roadblock other people can hit. Did you take the [tour]? [mcve] is also a good read, the [help/on-topic] has everything you ever wanted to know about asking a well-received question on this site. =) – Mathieu Guindon May 03 '18 at 02:21
  • I'd love to more effectively describe where and how I'm stumped, however, I do not have any more specific information in this case. I'm not asking anyone to "work for free". I legitimately thought this was a knowledge sharing forum. Perhaps I was mistaken. I am incredibly new to working with any sort of code. I've done some research into trying to find an answer on this but, without knowing proper terms and verbiage to search for, it becomes incredibly difficult. Again, I apologize if you felt I was asking anyone to "work for free", Rather than assist by sharing some knowledge. – Ashley Dodson May 03 '18 at 02:28
  • 2
    FWIW I took great care to word that comment, and *never said I felt that way* or accused you of asking that. What I said is that on this site posting specs without a question or a failing attempt, *can come across* as such. If you've done some research, tell us about it. If you've got any code that doesn't work, show us what you've tried. *Just trying to help you help us help you here*. It's not impossible that someone puts up a tutorial-like answer here, just know that it's more likely that the community deems it *too broad* to be a good fit for the site, as per [ask] and the [help/on-topic]. – Mathieu Guindon May 03 '18 at 02:44
  • 2
    *I'd like to set the tab to only be visible if the datasheet it contains has values* - so you'll need to figure out whether the datasheet for that tab (or its underlying data source?) has values. That first step alone could spawn a bunch of [specific questions](https://stackoverflow.com/a/6793133/1188513) that would be perfectly in-scope. Next you'll need to conditionally hide the tab; again how that's done is a good research topic in itself - [this post](https://stackoverflow.com/q/22610508/1188513) looks like something that might come up in that research... and solve half of your problem. – Mathieu Guindon May 03 '18 at 03:07
  • To make this, you won't be able to do it on Access itself. You will need VBA to create a code to check every subform on every tab and then hide if there is no data. If you don't know anything about coding in VBA, I'm afraid you will have to look for somebody to do it. If you know how to code in VBA, then the post of prior comment it's a good start. But just with Access you won't be able to do what you want. – Foxfire And Burns And Burns May 03 '18 at 11:18
  • @Mathieu Guindon - My apologies, I get cranky when I am tired and can't find what I am looking for. My main issue was not being sure how to evaluate if that subform has items in it. I mainly needed the first part, I know how to hide the tab - I did not know how to evaluate the subform to see if it has records. I believe someone answered that below. – Ashley Dodson May 04 '18 at 01:23

1 Answers1

2

While the question is somewhat broad, it can be achieved with a one-liner per page:

Private Sub Form_Current()
    Me![NameOfSomePage].Visible = Not Me![NameOfSubformOnThatPage].Form.RecordSet.RecordCount = 0
End Sub

Explanation:

Form_Current: event that occurs whenever the record on the main form changes

Me![NameOfSomePage].Visible =: Set the visibility of some page equal to

Not: True is False, False is True

Me![NameOfSubformOnThatPage].Form.Recordset.RecordCount = 0: Check if the underlying recordset for a certain subform contains 0 records

Note that, if 0 pages are displayed, the whole tab control disappears too.

Erik A
  • 31,639
  • 12
  • 42
  • 67