dbHiddenObject

J

Jim Pockmire

Can you help me clean up the code below? I expect it to hide the named table
and it doesn't.

Function HideTable(acTable As String)
Dim DB As DAO.Database
Dim tdf As DAO.TableDef
Set DB = CurrentDb
Set tdf = DB.TableDefs(acTable)
tdf.Attributes = tdf.Attributes And dbHiddenObject
End Function

Ps, I do want care to use "Application.SetHiddenAttribute..."
 
D

Dirk Goldgar

Jim Pockmire said:
Can you help me clean up the code below? I expect it to hide the
named table and it doesn't.

Function HideTable(acTable As String)
Dim DB As DAO.Database
Dim tdf As DAO.TableDef
Set DB = CurrentDb
Set tdf = DB.TableDefs(acTable)
tdf.Attributes = tdf.Attributes And dbHiddenObject
End Function

Ps, I do want care to use "Application.SetHiddenAttribute..."

Use "Or", not "And":

tdf.Attributes = tdf.Attributes Or dbHiddenObject
 
J

Jim Pockmire

I tried the substitution of "Or" for "And" and get a runtime 3001 error
"Invalid Argument". Ideas?
 
D

Dirk Goldgar

Jim Pockmire said:
I tried the substitution of "Or" for "And" and get a runtime 3001
error "Invalid Argument". Ideas?

The corrected code:

'----- start of code -----
Function HideTable(acTable As String)
Dim DB As DAO.Database
Dim tdf As DAO.TableDef
Set DB = CurrentDb
Set tdf = DB.TableDefs(acTable)
tdf.Attributes = tdf.Attributes Or dbHiddenObject
End Function

'----- end of code -----

works fine for me, though I would never use "acTable" as the name for a
variable or parameter, because there is a defined constant by that name.
However, as I said, this code works for me. Which exact line is raising
the error?
 
T

Tim Ferguson

tdf.Attributes = tdf.Attributes And dbHiddenObject

As Dirk says, you set a bit using the Or operator, not And.

Moreover, you do know that dbHiddenObject does not actually do what you
want, don't you? dbHiddenObject marks the object for deletion when the file
is closed.

You are probably better off with

Application.SetHiddenAttribute (ObjectType, ObjectName, fHidden)

which is in the help file


Hope that helps


Tim F
 
J

Jim Pockmire

Thank you,

I changed the name "acTable" to "strTable" and I no longer get the error
message. Is it possible (o reverse this and make the table visible (how)?
 
D

Dirk Goldgar

Jim Pockmire said:
Thank you,

I changed the name "acTable" to "strTable" and I no longer get the
error message.

Interesting. In my version, it worked even without that. I'm running
Access 2002 -- what are you running?
Is it possible (o reverse this and make the table
visible (how)?

How about this:

'------ start of code ------
Function ShowTable(strTable As String)
Dim DB As DAO.Database
Dim tdf As DAO.TableDef
Set DB = CurrentDb
Set tdf = DB.TableDefs(strTable)
tdf.Attributes = tdf.Attributes And (Not dbHiddenObject)
Set tdf = Nothing
Set DB = Nothing
End Function
'------ end of code ------
 
J

Jim Pockmire

Thanks again,

My testing has been with a local table which hides/unhides fine. However
when running the code for a linked table, once again I receive a runtime
3001 error "Invalid Argument". Is this behavior normal?
 
D

Dirk Goldgar

Jim Pockmire said:
Thanks again,

My testing has been with a local table which hides/unhides fine.
However when running the code for a linked table, once again I
receive a runtime 3001 error "Invalid Argument". Is this behavior
normal?

I hadn't tried this before, but I'm finding the same thing. My guess is
that, since this attribute is really supposed to be for use by the Jet
database engine, it won't let you set it for an attached table. That's
just a guess, though. If you *must* hide tables using the
dbHiddenObject attribute, instead of Application.SetHiddenObject (or
just naming them with the USys prefix), then I think you're probably
stuck as far as linked tables are concerned. You've been warned about
how dbHiddenObjects may be deleted -- at least in some versions of
Access -- when the database is compacted, right?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top