By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,955 Members | 1,756 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,955 IT Pros & Developers. It's quick & easy.

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

jbt007
P: 40
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:
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;"
  5.  
  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
  13.  
  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
  17.  
  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!

Thanks,
Dec 17 '10 #1
Share this Question
Share on Google+
2 Replies


100+
P: 122
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

jbt007
P: 40
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.