Private Sub bExportCurrentRecord_Click()
On Error GoTo Err_bExportCurrentRecord_Click
Dim sRecordID As String
Dim sLocation As String
Dim sFileName As String
sRecordID = Me.tbPositionID.Value
sLocation = "C:\"
sFileName = Format(Now(), "mmddyyyyhhmmss") & ".xls"
' MsgBox sFileName 'used for testing
If Dir(sLocation & sFileName) <> "" Then
'MsgBox "The " & sLocation & sFileName & "already exists!"
Kill sLocation & sFileName
Else
'MsgBox "file does not exists"
End If
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel97, "qCurrentDataRecord", sLocation & sFileName, True, ""
Beep
MsgBox "The current Position ID " & sRecordID & " and all related data was exported to your computer." & vbCrLf & vbLf & _
"The name of the file is '" & sFileName & "' and the file is located in the root of your C:\ drive.", vbInformation, "Exported >>> " & sLocation & sFileName
Exit_bExportCurrentRecord_Click:
Exit Sub
Err_bExportCurrentRecord_Click:
If Err = 75 Or Err = 3010 Then
Beep
MsgBox "The '" & sFileName & "'file is open." & vbCrLf & vbLf & "Please close the '" & sFileName & "' file before trying to export the data for current Position ID " & sRecordID & ".", vbCritical, "Export Error >>> " & sLocation & sFileName
Exit Sub
Else
MsgBox Err.Number, Err.Description
Resume Exit_bExportCurrentRecord_Click
End If
End Sub