Error Handling on using Common Dialog...

  • Thread starter ThriftyFinanceGirl
  • Start date


I have a procedure that runs an import based on the user choosing a file. I
want them to be able to cancel. I got the call for the common dialog from
the guys here on this group but it doesn't have error handling for the
occasion when the user chooses "cancel" instead of choosing a file.... Help?!
Don't know how to create a handler or where to put it exactly....

Public Function TaxExemptImport()

'Now open the small form that will show progress...
DoCmd.OpenForm "frmTaxExempt"

'Let's get the file name first....
Dim strFilter As String
Dim strInputFileName As String

strFilter = ahtAddFilterItem(strFilter, "Excel files (*.XLS)", "*.XLS")
strInputFileName = ahtCommonFileOpenSave( _
Filter:=strFilter, OpenFile:=True, _
DialogTitle:="Please select file to Import...", _

DoCmd.SetWarnings False
Application.Echo False
'bring data into the holding table
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9,
"TaxExemptImport", strInputFileName
Currently if the user chooses "cancel" in the Open dialog box, the code
stops on the "Docmd.TransferSpreadsheet" line. Where do I trap the error and

Jack Leach

Regardless of any issues with the common dialog, you should have error
handling in every single procedure. It's simple and essential to set up
basic error handling.

Public Function DoSomething()
On Error Goto Err_SomeName

'Your normal code here

'Cleanup here
Exit Function
MsgBox Err.Number & " " & Err.Description
Resume Exit_SomeName
End Function

That's the basic structure that should be in every procedure. Here's some
links on the subject...

Jack Leach

"I haven't failed, I've found ten thousand ways that don't work."
-Thomas Edison (1847-1931)

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question