Originally Posted by
hertfordkc
Why not exit the function and have a VBA onclose function in the report that cleans everything up?
Just a guess.
I will rework the process and let you know how it goes.
Thanks for pointing out the obvious...
Edit:
Code:
Option Compare Database
Option Explicit
Dim oDB As DAO.Database
Dim sTable As String
Private Sub Report_Open(Cancel As Integer)
Dim sFN As String
Dim tdfTable As TableDef
' Set Variables
sTable = "ContactLog"
' Create a temp database
sFN = CurrentProject.Path & "\Temp-" & Format(Now(), "yyyymmddhhNnss") & ".accdb"
modMain.CreateDatabaseDAO (sFN)
' Open the database
Set oDB = OpenDatabase(sFN)
' Create the table
oDB.Execute "CREATE TABLE " & sTable _
& " (lname CHAR, fname CHAR, cdate DATETIME, ctype CHAR, reason MEMO, outcome MEMO);"
' Link the table to this database
Set tdfTable = CurrentDb.CreateTableDef(sTable)
tdfTable.Connect = ";Database=" & sFN
tdfTable.SourceTableName = "ContactLog"
CurrentDb.TableDefs.Append tdfTable
Set tdfTable = Nothing
' Insert data from contacts
CurrentDb.Execute "INSERT INTO " & sTable & " ( lname, fname, cdate, ctype, reason, outcome ) SELECT tblContacts.lname, tblContacts.fname, tblContacts.cdate, tblContacts.ctype, tblContacts.reason, tblContacts.outcome FROM tblContacts INNER JOIN tblStudents ON (tblContacts.fname = tblStudents.fname) AND (tblContacts.lname = tblStudents.lname) WHERE tblStudents.Active = True"
' Insert data from weekly reports
CurrentDb.Execute "INSERT INTO " & sTable & " ( lname, fname, cdate, ctype, reason ) SELECT tblDaily.lname, tblDaily.fname, tblDaily.tdate AS cdate, 'W' AS ctype, tblDaily.comments AS reason FROM tblDaily WHERE tblDaily.comments Is Not Null"
' Close the temp database
Set oDB = Nothing
End Sub
Private Sub Report_Close()
' Remove the link to the temp table
CurrentDb.TableDefs.Delete sTable
' delete the database
Kill CurrentProject.Path & "\Temp-*.accdb"
End Sub
So, everything worked fine until it tried to delete the temp db...
Apparently there is a link to the temp db that set odb=nothing and clearing the table link doesn't fix.
I am lost. What am I missing.
Thanks for your help so far!!!