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:
- Application.SetHiddenAttribute acTable,"tblTxtRpt", True
This too did not work.
3. After creating the table I also tried;
- 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:
- '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,