Error Handling using Case - SOLVED

StuLux

Well-known Member
Joined
Sep 14, 2005
Messages
679
Office Version
  1. 365
Platform
  1. Windows
The following code is producing error 2501 at the line indicated, the code was working fine and I had previoulsy added error handling to effectively ignore this error but the error handler no longer picks up this error - can anybody explain why?

I have additional code in the Form_BeforeUpdate event but this merely runs through the controls on the form and produces msgbox prompts if any of the entries do not compy with certain rules. I'm not aware of making any chnages to this code from when it was working OK so I'm at a complete loss.

Code:
Private Sub cmdClosefrmProjects_Click()
On Error GoTo Err_cmdClosefrmProjects_Click

    Call Audit

    If Me.Dirty Then
        DoCmd.RunCommand acCmdSaveRecord 'ERROR OCCURS HERE
    End If
    DoCmd.Close acForm, Me.Name

Exit_cmdClosefrmProjects_Click:
    Exit Sub

Err_cmdClosefrmProjects_Click:
    
    Select Case Err.Number
        Case 2501 'Ignores the "run command action was cancelled" error
        Case Else
            msgbox "Error " & Err.Number & ": " & Err.Description, vbCritical, "modName.FunctionName"
    End Select
    
    Resume Exit_cmdClosefrmProjects_Click
    
End Sub
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
I found the problem was that I had set the General Options in VBA to "Break on all errors" without realising what this actually did - doh.
 
Upvote 0

Forum statistics

Threads
1,214,945
Messages
6,122,397
Members
449,081
Latest member
JAMES KECULAH

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top