Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dialog Box Error Message

Status
Not open for further replies.

wyvern621

Technical User
Nov 11, 2005
19
US
Afternoon All...

I added a module to open a Dialog Box to import some files. Works great unless you hit cancel, then you get a runtime error 2501 "The RunCommand action was cancelled".

Here's the code:

Function GetPMSL()

DoCmd.RunCommand acCmdImport


End Function


I want to add an error handling messge and close the dialog box, but how?

Thanks.

ChiTownDiva [ponytails]
 
Use the wizard to create a command button, it will give you an outline for error handling. You will also find a great deal on the internet on the subject.
 
You can also get some good information on error handling in VBA Help.

For me, I've developed the following flow for my subs and functions:

Code:
Public Sub GetPMSL()
On Error GoTo PROC_ERR [green]' this is *always* my first line[/green]

   [green]' Your procedure's code goes here[/green]
   DoCmd.RunCommand acCmdImport

PROC_EXIT:[green]
    ' You will make it here if you have no errors.
    ' The next line ensures you leave the sub/function
    ' before hitting your error routine[/green]
    Exit Sub
PROC_ERR:[green]
    ' Your error handling routine goes here.
    ' Be sure to read up on the various error response
    ' options!
    ' Here is a method for trapping a specific error[/green]
    If Err.Number = 2501 Then[green]
        ' user cancelled dialog from RunCommand[/green]
        Err.Clear
    Else[green]
        ' all other errors handled here...[/green]
    
    End If
End Sub

Hope this helps. Do research error handling as Remou advised. It's an important part of making your application more robust.

- Larry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top