Private Sub cmdExportStudyData_Click()
On Error GoTo Err_cmdExportStudyData_Click
Dim strStudy, strDate, strFileName, strExportFile, strExportFolder, strSpec, strDoc As String
Dim strMsgTitle, strMsgInfo As String
strDoc = "qryExportStudyData"
strStudy = cmbStudies
strDate = Format(Date, "YYYYMMMDD")
strFileName = strStudy & " sero (" & strDate & ").txt"
strSpec = "exqryExportStudyData"
strExportFolder = "\ExportResults\"
strExportPath = CurrentProject.Path & strExportFolder
strExportFile = CurrentProject.Path & strExportFolder & strFileName
strMsgTitle = "Empyema Study"
strMsgInfo = vbInformation + vbOKOnly
strMsgError = vbCritical + vbOKOnly
If IsNull(cmbStudies) Then
MsgBox "Please select a study first", vbExclamation, "Empyema Study"
Else
DoCmd.TransferText acExportDelim, strSpec, strDoc, strExportFile, False
MsgBox "Your data file is saved as: " & Chr(13) & strFileName & Chr(13) & "This file overwrites any previous data file made today." & Chr(13) & Chr(13) & "And is saved here: " & Chr(13) & strExportFile, strMsgInfo, strMsgTitle
Shell "notepad.exe " & strExportFile, vbNormalFocus
End If
Exit_cmdExportStudyData_Click:
Exit Sub
Err_cmdExportStudyData_Click:
Select Case Err.Number
Case 3044
'destination folder does not exist, replace default warning with this:
MsgBox "Could not write file." & Chr(13) & "Please ensure the subfolder " & strExportFolder & " exists in the database directory, then try again." & Chr(13) & Chr(13) & "Full file path expected:" & Chr(13) & strExportPath, strMsgError, strMsgTitle
Case Else
Msg = "Error # " & str(Err.Number) & Chr(13) & Err.Description
MsgBox Msg, , "Error", Err.HelpFile, Err.HelpContext
End Select
Resume Exit_cmdExportStudyData_Click
End Sub