Hi I've got the below code that users will use to import an excel spreadsheet into access. While working on it, I found out that it won't import the excel doc in unless the file name and sheet name in excel match. If they don't, it just won't import the spreadsheet in and will say "the search key is not found". Is it possible to change that error message to be more specific? Any idea how to code that if so?
Code:
Private Sub bttnProcessIt_Click()
Dim wdShell As Object, strFile_Path As String, strResponse As String, fd As FileDialog
On Error GoTo ImportIt_Err
MsgBox "Please remember that the file name AND the sheet name in Excel must be named 'CRM'.", vbOKOnly
' Prompt user for file path for the Raw CRM spreadsheet
Set fd = Application.FileDialog(msoFileDialogFilePicker)
With fd
.Title = "Please select the CRM file for processing"
.InitialFileName = "F:\CRM"
.Filters.Add "Excel Spreadsheets", "*.xlsx", 1
.FilterIndex = 1
.Show
If .SelectedItems.Count = 0 Then
Exit Sub
Else
strFile_Path = .SelectedItems.Item(1)
End If
End With
DoCmd.SetWarnings (False)
DoCmd.OpenQuery "qryClear_RawAuditTemp"
DoCmd.OpenQuery "qryClear_RawAudit"
DoCmd.RunSavedImportExport "Import-CRM"
DoCmd.OpenQuery "qryCleanRawAuditData"
DoCmd.RunSavedImportExport "Export-Last Name Match Report"
DoCmd.RunSavedImportExport "Export-First and Last Name Match Report"
DoCmd.RunSavedImportExport "Export-Address Match Report"
DoCmd.RunSavedImportExport "Export-Phone Number Match Report"
DoCmd.RunSavedImportExport "Export-Employee Views Report"
DoCmd.RunSavedImportExport "Export-No Action Views Report"
DoCmd.RunSavedImportExport "Export-Summary Report"
DoCmd.Close acForm, Me.Name
strResponse = MsgBox("The CRM audit has been successfully imported and the exported files are located in CRM Audit Tool folder!")
ImportIt_Exit:
Exit Sub
ImportIt_Err:
MsgBox Error$
Resume ImportIt_Exit
End Sub