gojets1721
Registered User.
- Local time
- Today, 01:45
- Joined
- Jun 11, 2019
- Messages
- 430
Hi I have a code written (see below) that prompts the user upon opening access to import in an excel file. Its a form and has just a big 'import' button. When the user presses it, the windows dialog box opens for them to select a file. However, if they press cancel or X out of the dialog box, a nasty "run time error 5" error box appears. Now the user can just select 'end' and get out of it, but it would be nice if it was possible for them to be sent just back to the form if they cancel out with no error message appearing. Any idea?
Code:
Public Sub bttnProcessIt_Click()
Dim wdShell As Object
' 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
Application.FileDialog(msoFileDialogOpen).Title = "Please select the CRM file for processing"
Application.FileDialog(msoFileDialogOpen).InitialFileName = "F:\CRM"
Application.FileDialog(msoFileDialogOpen).Filters.Add "Excel Spreadsheets", "*.xlsx", 1
Application.FileDialog(msoFileDialogOpen).FilterIndex = 1
Application.FileDialog(msoFileDialogOpen).Show
strFile_Path = Application.FileDialog(msoFileDialogOpen).SelectedItems.Item(1)
DoCmd.SetWarnings (WarningsOff)
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
Last edited: