How to hide a table that is made with SQL "CREATE TABLE"?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jbt007
    New Member
    • Jul 2010
    • 40

    How to hide a table that is made with SQL "CREATE TABLE"?

    All,

    Access 2003 - WinXP

    I thought this would be a no brainer, but it seems to be a perplexing problem. I have a simple table I use for importing several text reports, use VBA to run through the report to move data into tables. The temp table stays in access (tblTxtRpt), until the next report is imported, I then use SQL to DROP TABLE and CREATE TABLE to recreate it. This is because the table has an autonumber field that numbers the text report lines when it's imported. It is very important the records stay in the exact order of the report because data records on the report are on several lines.

    What I want to do is hide this table so it doesn't show. Here are the things I have tried:

    1. Naming the table MsysTxtRpt - Thinking that Access would consider this a system table and keep it hidden. This didn't work.

    2. After creating the table I added code:
    Code:
    Application.SetHiddenAttribute acTable,"tblTxtRpt", True
    This too did not work.

    3. After creating the table I also tried;
    Code:
    Access.CurrentDb.TableDefs("tblTxtRpt").Attributes = dbHiddenObject
    which also failed.

    The reason I use DROP TABLE and CREATE TABLE is that access will not let you start an AutoNumber field over at "1" after you "DELETE tblTxtRpt.* FROM tblTxtRpt" It picks up where the last record ended. Due to the number of records (10,000+) in the txt report and the number of reports being imported, the AutoNumber field would quickly get very large and out of control. Dropping the table and adding it again solved this issue.

    Here's my code for the process:

    Code:
        'Import the text report into the temp table.
        'Initialize variables
        Set db = Access.CurrentDb
        strSQL = "DROP TABLE tblTxtRpt;"
        
        'Delete the tblTxtRpt table if it is still in the db
        For Each tbl In db.TableDefs
            If tbl.name = "tblTxtRpt" Then
                db.Execute strSQL, dbFailOnError
                Exit For
            End If
        Next
        
        'Create a new tblTxtRpt to import the text report (Projection, Weekly, Monthly, etc. all use same table...
        strSQL = "CREATE TABLE tblTxtRpt ([RawRec] Text(200), [RecID] AutoIncrement);"
        db.Execute strSQL, dbFailOnError
        
        'Hide the temporary table (tblTxtRpt)...
        Access.CurrentDb.TableDefs("tblTxtRpt").Attributes = dbHiddenObject
        'To unhide, unremark the below line and remark out the line above...
        'Access.CurrentDb.TableDefs("tblTxtRpt").Attributes = 0
    Any thoughts or suggestions from the experts out there would put you on my Christmas, Hanukkah, etc. list!

    Thanks,
  • gershwyn
    New Member
    • Feb 2010
    • 122

    #2
    I'm not sure how to programmaticall y hide a table, but one thing you might try is instead of dropping the entire table, just drop the autonumber field.

    Code:
    ALTER TABLE tblTextRpt DROP RecID
    ALTER TABLE tblTextRpt ADD RecID Counter
    If you use that to reset the autonumber field of an already hidden table, it will stay hidden.

    Comment

    • jbt007
      New Member
      • Jul 2010
      • 40

      #3
      gershwyn - Thanks for the suggestion, however in testing I find that dropping just the field and adding again does not reset the AutoNumber back to 1. I have no idea how access trcks this number, but it doesn't seem to be reset when the field is deleted / re-added.

      Comment

      Working...