|
|
Question : Access 2003 Crashes on reference to TableDefs - Why?
|
|
This code called from a form field change event causes Access 2003 to crash. The DAO 3.6 is enabled.
Sub HideUnhideTable(txtTableName As String, bolEnable As Boolean) Dim tdf As TableDef For Each tdf In CurrentDb.TableDefs ' <--This statement crashes If (tdf.Name = txtTableName) Then If bolEnable Then tdf.Attributes = 0 Else tdf.Attributes = dbHiddenObject End If Next tdf End Sub
Many tables exist in the database. Why would this cause Access to crash. 'Found nothing in M$ knowledge base.
|
Answer : Access 2003 Crashes on reference to TableDefs - Why?
|
|
Try setting a variable for the Database:
dim dbs as DAO.Databse
Set dbs = Currentdb
for each tdf in dbs.tabledefs etc etc
I'd advise you to be very careful when setting attributes for tables ... the way you're going about doing this, you would erase ALL the attibutes of your table except for the Hidden value ... instead, you'd probably want to OR them together:
If (tdf.Name = txtTableName) Then If bolEnable Then tdf.Attributes = tdf.Attributes OR NOT dbHiddenObject Else tdf.Attributes = tdf.Attributes OR dbHiddenObject End If
|
|
|
|