469,888 Members | 1,236 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,888 developers. It's quick & easy.

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


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:
Expand|Select|Wrap|Line Numbers
  1. Application.SetHiddenAttribute acTable,"tblTxtRpt", True
This too did not work.

3. After creating the table I also tried;
Expand|Select|Wrap|Line Numbers
  1. 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:

Expand|Select|Wrap|Line Numbers
  1.     'Import the text report into the temp table.
  2.     'Initialize variables
  3.     Set db = Access.CurrentDb
  4.     strSQL = "DROP TABLE tblTxtRpt;"
  6.     'Delete the tblTxtRpt table if it is still in the db
  7.     For Each tbl In db.TableDefs
  8.         If tbl.name = "tblTxtRpt" Then
  9.             db.Execute strSQL, dbFailOnError
  10.             Exit For
  11.         End If
  12.     Next
  14.     'Create a new tblTxtRpt to import the text report (Projection, Weekly, Monthly, etc. all use same table...
  15.     strSQL = "CREATE TABLE tblTxtRpt ([RawRec] Text(200), [RecID] AutoIncrement);"
  16.     db.Execute strSQL, dbFailOnError
  18.     'Hide the temporary table (tblTxtRpt)...
  19.     Access.CurrentDb.TableDefs("tblTxtRpt").Attributes = dbHiddenObject
  20.     'To unhide, unremark the below line and remark out the line above...
  21.     'Access.CurrentDb.TableDefs("tblTxtRpt").Attributes = 0
Any thoughts or suggestions from the experts out there would put you on my Christmas, Hanukkah, etc. list!

Dec 17 '10 #1
2 3039
122 100+
I'm not sure how to programmatically hide a table, but one thing you might try is instead of dropping the entire table, just drop the autonumber field.

Expand|Select|Wrap|Line Numbers
  1. ALTER TABLE tblTextRpt DROP RecID
  2. ALTER TABLE tblTextRpt ADD RecID Counter
If you use that to reset the autonumber field of an already hidden table, it will stay hidden.
Dec 17 '10 #2
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.
Dec 21 '10 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

8 posts views Thread by cainlevy | last post: by
2 posts views Thread by Alanoly J. Andrews | last post: by
7 posts views Thread by alessandro menchini | last post: by
5 posts views Thread by GHUM | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.