Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2010
    Posts
    186

    Unanswered: page of tabcontrol visible if subform has records

    i use this VBA code in main form on current to hide subforms with no records.
    this particular main form has 4 subforms so I am using a tabcontrol to place the forms in. The 1st main form (not shown in code) always has records..the other 3 may or may not
    the first on and the last one have table record sources
    the middle on is a query

    the VBA doesn't work on the main form that has the tab control?
    no errors
    Private Sub Form_Current()
    With Me![sfViewSlmnNotes].Form
    .Visible = (.RecordsetClone.RecordCount > 0)
    With Me![RQTHISTORYsf].Form
    .Visible = (.RecordsetClone.RecordCount > 0)
    With Me![frmsfTedsLine2].Form
    .Visible = (.RecordsetClone.RecordCount > 0)

    End With
    End With
    End With

    ideally - I would like to hide the page altogether so that the user will not be looking in them when there are no records
    does anyone know how I would modify this to work?

  2. #2
    Join Date
    Mar 2009
    Location
    Dorset
    Posts
    119
    Your with statements don't look right - I don't think they need to be nested so try changing to the following:


    With Me![sfViewSlmnNotes].Form
    .Visible = (.RecordsetClone.RecordCount > 0)
    End With

    With Me![RQTHISTORYsf].Form
    .Visible = (.RecordsetClone.RecordCount > 0)
    End With

    With Me![frmsfTedsLine2].Form
    .Visible = (.RecordsetClone.RecordCount > 0)
    End With
    Regards
    JD

    Software-Matters

  3. #3
    Join Date
    Jun 2010
    Posts
    186
    Thanks!

    I went ahead and changed the with statement but I'm getting the same results. No error, but not triggering.
    Some things have come to mind -

    I want the entire page hidden if there is no subform records - which means that Access will have to show page 0 (always show page 0) then page 2 on one instance; page 0 then page 1 on another; page 0 then page 1 and 3 on another; page 0 then nothing on another. I added the page 0 as well but that didn't change the result. All subfoms are visible.
    I also tried this code in the mainform current event -
    Me.Tabctl75.PageIndex(1).Visible = Me.[sfViewSlmnNotes].Form.Recordset.Recordcount >0)
    Me.Tabctl75.PageIndex(2).Visible = Me.[RQTHISTORYsf].Form.Recordset.Recordcount >0)
    Me.Tabctl75.PageIndex(2).Visible = Me.[frmsfTedLine2].Form.Recordset.Recordcount >0)
    and with this I tested different examples - none hidden at all

    First, I'm not sure tab control is what I should be using. Isn't the logic behind the tab control to stack info so that it's all visible? And that's why I would use it?

    Second, I noticed some variation in the subforms when I clicked through them in design view that makes me think they didn't load on the page correctly. For example, the names aren't consistent.....my page 1 had the subform name as the name, but my pages 2 & 3 were assigned something by access. I was so confused I changed them to all read the same....but maybe I should try to relink the subforms on the pages? Is there a correct and incorrect way to load these that would cause the code to fail?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •