N
newsgroups
I have a report that within the Report_Open event, I create a
temporary database and create a linked table to it (using the code
fragment below).
Dim tdfNew As TableDef
Dim RS As Recordset
Dim wrkDefault As Workspace
Dim dbsTemp As Database
Dim strTableName As String
' Get default Workspace.
Set wrkDefault = DBEngine.Workspaces(0)
' Make sure there isn't already a file with the name of the new
database.
If Dir(mstrTempDatabase) <> "" Then Kill mstrTempDatabase
'Create a new temp database
Set dbsTemp = wrkDefault.CreateDatabase(mstrTempDatabase,
dbLangGeneral)
' Delete the link to the temp table if it exists
If TableExists(mstrTableName) Then CurrentDb.TableDefs.Delete
mstrTableName
' Create the temp table
Set tdfNew = dbsTemp.CreateTableDef(mstrTableName)
With tdfNew
.Fields.Append .CreateField("Resource Name", dbText)
.Fields.Append .CreateField("Profile", dbMemo)
dbsTemp.TableDefs.Append tdfNew
End With
dbsTemp.TableDefs.Refresh
' Link to the Import tables in the temp MDB
Dim tdfLinked As TableDef
Set tdfLinked = CurrentDb.CreateTableDef(mstrTableName)
tdfLinked.Connect = ";DATABASE=" & mstrTempDatabase
tdfLinked.SourceTableName = mstrTableName
CurrentDb.TableDefs.Append tdfLinked
CurrentDb.TableDefs.Refresh
RefreshDatabaseWindow
Now the problem. I can delete the linked table, but the other
temporary database is still open and I cannot delete it. It is
released about 5-10 seconds after the report has been closed.
Can someone help me on forcing a close on this report so I can delete
the temporary file.
Thanks in advance.
temporary database and create a linked table to it (using the code
fragment below).
Dim tdfNew As TableDef
Dim RS As Recordset
Dim wrkDefault As Workspace
Dim dbsTemp As Database
Dim strTableName As String
' Get default Workspace.
Set wrkDefault = DBEngine.Workspaces(0)
' Make sure there isn't already a file with the name of the new
database.
If Dir(mstrTempDatabase) <> "" Then Kill mstrTempDatabase
'Create a new temp database
Set dbsTemp = wrkDefault.CreateDatabase(mstrTempDatabase,
dbLangGeneral)
' Delete the link to the temp table if it exists
If TableExists(mstrTableName) Then CurrentDb.TableDefs.Delete
mstrTableName
' Create the temp table
Set tdfNew = dbsTemp.CreateTableDef(mstrTableName)
With tdfNew
.Fields.Append .CreateField("Resource Name", dbText)
.Fields.Append .CreateField("Profile", dbMemo)
dbsTemp.TableDefs.Append tdfNew
End With
dbsTemp.TableDefs.Refresh
' Link to the Import tables in the temp MDB
Dim tdfLinked As TableDef
Set tdfLinked = CurrentDb.CreateTableDef(mstrTableName)
tdfLinked.Connect = ";DATABASE=" & mstrTempDatabase
tdfLinked.SourceTableName = mstrTableName
CurrentDb.TableDefs.Append tdfLinked
CurrentDb.TableDefs.Refresh
RefreshDatabaseWindow
Now the problem. I can delete the linked table, but the other
temporary database is still open and I cannot delete it. It is
released about 5-10 seconds after the report has been closed.
Can someone help me on forcing a close on this report so I can delete
the temporary file.
Thanks in advance.