Connecting Tech Pros Worldwide Forums | Help | Site Map

Help hiding table in VB

Needs Regular Fix
 
Join Date: Oct 2007
Location: Hull,UK
Posts: 297
#1: 3 Weeks Ago
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
Expand|Select|Wrap|Line Numbers
  1. Dim tdf As DAO.TableDef
  2.     For Each tdf In CurrentDb.TableDefs
  3.         tdf.Attributes = dbHiddenObject
  4.     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
best answer - posted by ADezii
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:
    Expand|Select|Wrap|Line Numbers
    1. Public Sub HideTable(strTableName As String, blnHide As Boolean)
    2.   Application.SetHiddenAttribute acTable, strTableName, blnHide
    3. End Sub
  2. Sample usage:
    Expand|Select|Wrap|Line Numbers
    1. 'To Hide Table1
    2. Call HideTable("Table1", True)
    3.  
    4. 'To Unhide Table1
    5. Call HideTable("Table1", False)
  3. To Hide/Unhide ALL Tables excluding System and Temporary Tables:
    Expand|Select|Wrap|Line Numbers
    1. Dim tdf As DAO.TableDef
    2.  
    3. For Each tdf In CurrentDb.TableDefs
    4.   If Mid$(tdf.Name, 2, 3) <> "Sys" And Left$(tdf.Name, 1) <> "~" Then
    5.     Call HideTable(tdf.Name, True)      'Hide
    6.     'Call HideTable(tdf.Name, False)    'Unhide
    7.   End If
    8. Next
  4. Some other useless code:
    Expand|Select|Wrap|Line Numbers
    1. Public Function fIsTableHidden(strTableName As String) As Boolean
    2.   fIsTableHidden = Application.GetHiddenAttribute(acTable, strTableName)
    3. End Function
  5. Useless code usage (is that redundant?):
    Expand|Select|Wrap|Line Numbers
    1. If fIsTableHidden("Table1") Then
    2.   MsgBox "Table1 is Hidden"
    3. Else
    4.   MsgBox "Table1 is NOT Hidden"
    5. End If

ADezii's Avatar
Expert
 
Join Date: Apr 2006
Location: Philadelphia
Posts: 5,226
#2: 3 Weeks Ago

re: Help hiding table in VB


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:
    Expand|Select|Wrap|Line Numbers
    1. Public Sub HideTable(strTableName As String, blnHide As Boolean)
    2.   Application.SetHiddenAttribute acTable, strTableName, blnHide
    3. End Sub
  2. Sample usage:
    Expand|Select|Wrap|Line Numbers
    1. 'To Hide Table1
    2. Call HideTable("Table1", True)
    3.  
    4. 'To Unhide Table1
    5. Call HideTable("Table1", False)
  3. To Hide/Unhide ALL Tables excluding System and Temporary Tables:
    Expand|Select|Wrap|Line Numbers
    1. Dim tdf As DAO.TableDef
    2.  
    3. For Each tdf In CurrentDb.TableDefs
    4.   If Mid$(tdf.Name, 2, 3) <> "Sys" And Left$(tdf.Name, 1) <> "~" Then
    5.     Call HideTable(tdf.Name, True)      'Hide
    6.     'Call HideTable(tdf.Name, False)    'Unhide
    7.   End If
    8. Next
  4. Some other useless code:
    Expand|Select|Wrap|Line Numbers
    1. Public Function fIsTableHidden(strTableName As String) As Boolean
    2.   fIsTableHidden = Application.GetHiddenAttribute(acTable, strTableName)
    3. End Function
  5. Useless code usage (is that redundant?):
    Expand|Select|Wrap|Line Numbers
    1. If fIsTableHidden("Table1") Then
    2.   MsgBox "Table1 is Hidden"
    3. Else
    4.   MsgBox "Table1 is NOT Hidden"
    5. End If
Needs Regular Fix
 
Join Date: Oct 2007
Location: Hull,UK
Posts: 297
#3: 3 Weeks Ago

re: Help hiding table in VB


i modified the code slightly and get an error, this is what i modified it to
Needs Regular Fix
 
Join Date: Oct 2007
Location: Hull,UK
Posts: 297
#4: 3 Weeks Ago

re: Help hiding table in VB


Expand|Select|Wrap|Line Numbers
  1. Function SecureTable(qLock As Boolean)
  2. Dim tdf As DAO.TableDef
  3.     For Each tdf In CurrentDb.TableDefs
  4.         If Mid$(tdf.Name, 2, 3) <> "Sys" And Left$(tdf.Name, 1) <> "~" Then
  5.             Application.SetHiddenAttribute acTable, tdf, qLock
  6.         End If
  7.     Next
  8. End Function
error is type mismatch highlighting "SetHiddenAttribute"
have i gone too far (in my ADezii MOD)?
Needs Regular Fix
 
Join Date: Oct 2007
Location: Hull,UK
Posts: 297
#5: 3 Weeks Ago

re: Help hiding table in VB


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

Thanks for the help
Reply