In the frmMain, I have a button that creates a table and opens a report. I won't show all code used to create and populate the table (unless you need to see it); but, here is the snippet that displays the report:
sReport = "Property Report"
DoCmd.OpenReport sReport, acViewReport
The report uses the created table as the Record Source for the Report. (I have also tried to use a query as the Record Source with the same results).
On the Report, there are 3 buttons one to Exit, one to Print, and one to Save the Report to a PDF file.
Private Sub btnExit_Click()
DoCmd.Close acReport, Me.Name, acSaveYes
DoCmd.OpenForm ("frmMain")
End Sub
Private Sub btnPrint_Click()
DoCmd.OpenReport "Property Report", acViewNormal
End Sub
Private Sub btnSave_Click()
Dim fDialog As FileDialog 'In tools/references - Enable Microsoft Office 16.0 Object Library
Dim result As Integer
Dim sFile, sTemp As String
Dim fileLocation As String
Dim sPropName As String
Dim i As Integer
sPropName = Replace(gsCurrentPropertyName, " ", "_")
fileLocation = Date
fileLocation = Replace(fileLocation, "/", "-")
fileLocation = "Property_Report_" & sPropName & "_" & fileLocation & ".pdf"
Set fDialog = Application.FileDialog(msoFileDialogSaveAs)
'Optional: FileDialog properties
fDialog.InitialFileName = fileLocation
'Show the dialog. -1 means success!
If fDialog.Show = -1 Then
sFile = fDialog.SelectedItems(1)
i = InStr(1, sFile, ".")
If i = 0 Then
sFile = sFile & ".pdf"
Else
sTemp = Right(sFile, Len(sFile) - i + 1)
If LCase(sTemp) <> ".pdf" Then
sFile = Left(sFile, i - 1) & "pdf"
End If
End If
DoCmd.OutputTo acOutputReport, "", acFormatPDF, sFile
End If
End Sub
In all cases, neither the Print nor the Save button cause the Report to return to frmMain. The Exit button must be used to end the Report.
When the Report is ended, the frmMain is displayed without error. However, when I attempt to create a new report, I Drop the table and then create and populate it. If I simply looked at the Report or Printed the report, everything works fine. But if I
Save the Report to a PDF and then Exit, the table remains locked and I get the 3211 error when I attempt to delete the table.
Public Sub DropTempTable()
If Not IsNull(DLookup("Name", "MSysObjects", "Name='tblTemp'")) Then
sSql = "DROP TABLE [tblTemp];"
CurrentDb.Execute sSql
End If
End Sub
I get a error message. It says Run-Time error '3211':
"The database engine could not lock the table 'tblTemp' because it is already in use by another person or process."
P.S. I have search the internet for this problem and have found other posting of this problem but no solution.
Thank You
Thank You