Help hiding table in VB

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Dan2kx
    Contributor
    • Oct 2007
    • 365

    #1

    Help hiding table in VB

    Hello to all you forum goers,

    I have another one of my random (to most people) questions

    i want a vb routine to hide and unhide tables in access (obviously)
    i was thinking of something like this
    Code:
    Dim tdf As DAO.TableDef
        For Each tdf In CurrentDb.TableDefs
            tdf.Attributes = dbHiddenObject
        next
    but i want to exclude the system tables etc,
    and im not sure what the attribude code is for a normal table to unhide it,

    im sure this is an easy one for the experts

    thanks in advance

    Dan
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    I've created a simple Public Sub-Routine for you that will Hide/Unhide any Table. Simply pass to the Routine the Table Name (String), and a Boolean Value (True/False) indicating whether or not to Hide the Table or Unhide it.
    1. Sub-Routine definition:
      Code:
      Public Sub HideTable(strTableName As String, blnHide As Boolean)
        Application.SetHiddenAttribute acTable, strTableName, blnHide
      End Sub
    2. Sample usage:
      Code:
      'To Hide Table1
      Call HideTable("Table1", True)
      
      'To Unhide Table1
      Call HideTable("Table1", False)
    3. To Hide/Unhide ALL Tables excluding System and Temporary Tables:
      Code:
      Dim tdf As DAO.TableDef
      
      For Each tdf In CurrentDb.TableDefs
        If Mid$(tdf.Name, 2, 3) <> "Sys" And Left$(tdf.Name, 1) <> "~" Then
          Call HideTable(tdf.Name, True)      'Hide
          'Call HideTable(tdf.Name, False)    'Unhide
        End If
      Next
    4. Some other useless code:
      Code:
      Public Function fIsTableHidden(strTableName As String) As Boolean
        fIsTableHidden = Application.GetHiddenAttribute(acTable, strTableName)
      End Function
    5. Useless code usage (is that redundant?):
      Code:
      If fIsTableHidden("Table1") Then
        MsgBox "Table1 is Hidden"
      Else
        MsgBox "Table1 is NOT Hidden"
      End If
    Last edited by NeoPa; Nov 8 '09, 11:25 PM. Reason: Removed Quote for Best Answer.

    Comment

    • Dan2kx
      Contributor
      • Oct 2007
      • 365

      #3
      i modified the code slightly and get an error, this is what i modified it to

      Comment

      • Dan2kx
        Contributor
        • Oct 2007
        • 365

        #4
        Code:
        Function SecureTable(qLock As Boolean)
        Dim tdf As DAO.TableDef
            For Each tdf In CurrentDb.TableDefs
                If Mid$(tdf.Name, 2, 3) <> "Sys" And Left$(tdf.Name, 1) <> "~" Then
                    Application.SetHiddenAttribute acTable, tdf, qLock
                End If
            Next
        End Function
        error is type mismatch highlighting "SetHiddenAttri bute"
        have i gone too far (in my ADezii MOD)?

        Comment

        • Dan2kx
          Contributor
          • Oct 2007
          • 365

          #5
          Ahh think i got it, needed to use tdf.name on line #5

          Thanks for the help

          Comment

          Working...