Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
on error resume next
I have this module that runs when an option button is clicked on a user
form. There is a done and cancel button also. It runs well, the only time it doesn't run is if the user opens the wrong workbook. I noticed when this happens that Excel doesn't quit the form. It might be fixed now but I thought I would put in "on error resume next"? Basically if the first macro doesn't run correctly then the other two don't need to run either. Should I just put the resume next enclosed in the if/then or after every procedure? Thanks, --------macro---------- Sub optReformatDepts_Click() If Fprocess1 = True And Fprocess2 = True Then Fprocess3 = False If optReformatDepts.Value = True Then Call ReformatDepts.ColorDivHeaders On Error Resume Next Call ReformatDepts.StatusRowHeader On Error Resume Next Call ReformatDepts.HideXtraColumns On Error Resume Next Call ReformatDepts.ReportSetup Fprocess3 = True End If Else MsgBox "Please check for duplicates and save first." End If End Sub --------whole user form----------- Dim Fprocess1 As Boolean Dim Fprocess2 As Boolean Dim Fprocess3 As Boolean Sub cmdCancel_Click() If MsgBox("Are you sure you want to cancel?", _ vbYesNo + vbQuestion, _ "Cancel") = vbYes Then Unload Me End Sub Sub cmdOkay_Click() If Fprocess1 = True And Fprocess2 = True And Fprocess3 = True Then Unload Me Else MsgBox " All options must be completed before closing" End If End Sub Sub optCkforDupes_Click() Dim nResult As Long Debug.Print frRptDate Debug.Print toRptDate Fprocess1 = False If optCkforDupes.Value = True Then nResult = MsgBox(prompt:="From: " & FrReptDate & vbNewLine & "To: " & ToReptDate, Buttons:=bvOKCancel, Title:="report Date") End If If nResult = vbOK Then Call createXLdb.CkforDupes Fprocess1 = True End If End Sub Sub optSaveIndesign_Click() If Fprocess1 = True Then Fprocess2 = False If optSaveIndesign.Value = True Then Call saveIndesign.saveIndesign Fprocess2 = True End If Else MsgBox "Please check for duplicates first." End If End Sub Sub optReformatDepts_Click() If Fprocess1 = True And Fprocess2 = True Then Fprocess3 = False If optReformatDepts.Value = True Then Call ReformatDepts.ColorDivHeaders On Error Resume Next Call ReformatDepts.StatusRowHeader On Error Resume Next Call ReformatDepts.HideXtraColumns On Error Resume Next Call ReformatDepts.ReportSetup Fprocess3 = True End If Else MsgBox "Please check for duplicates and save first." End If End Sub Private Sub UserForm_Click() End Sub |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
on error resume next
Janis,
The on error resume next structure can be used at the start of the subroutine and will automatically be used to deal with any error in the program until you change it in the code. So just adding it to the start of the code will propagate it through the entire program. I wouldn't recommend this method though, since it's a encompasses errors that could occur. I would suggest the use an errorhandler routine that deals with the error specifically. Something along these lines. Less chance of incorrectly dealing with an unanticipated error. Private Sub CommandButton1_Click() On Error GoTo ErrHandler 'Your Code.... Exit Sub ErrHandler: Select Case Err.Number Case 9 Resume Case Else MsgBox Err.Number & " " & Err.Description End Select End Sub HTH Cal "Janis" wrote: I have this module that runs when an option button is clicked on a user form. There is a done and cancel button also. It runs well, the only time it doesn't run is if the user opens the wrong workbook. I noticed when this happens that Excel doesn't quit the form. It might be fixed now but I thought I would put in "on error resume next"? Basically if the first macro doesn't run correctly then the other two don't need to run either. Should I just put the resume next enclosed in the if/then or after every procedure? Thanks, --------macro---------- Sub optReformatDepts_Click() If Fprocess1 = True And Fprocess2 = True Then Fprocess3 = False If optReformatDepts.Value = True Then Call ReformatDepts.ColorDivHeaders On Error Resume Next Call ReformatDepts.StatusRowHeader On Error Resume Next Call ReformatDepts.HideXtraColumns On Error Resume Next Call ReformatDepts.ReportSetup Fprocess3 = True End If Else MsgBox "Please check for duplicates and save first." End If End Sub --------whole user form----------- Dim Fprocess1 As Boolean Dim Fprocess2 As Boolean Dim Fprocess3 As Boolean Sub cmdCancel_Click() If MsgBox("Are you sure you want to cancel?", _ vbYesNo + vbQuestion, _ "Cancel") = vbYes Then Unload Me End Sub Sub cmdOkay_Click() If Fprocess1 = True And Fprocess2 = True And Fprocess3 = True Then Unload Me Else MsgBox " All options must be completed before closing" End If End Sub Sub optCkforDupes_Click() Dim nResult As Long Debug.Print frRptDate Debug.Print toRptDate Fprocess1 = False If optCkforDupes.Value = True Then nResult = MsgBox(prompt:="From: " & FrReptDate & vbNewLine & "To: " & ToReptDate, Buttons:=bvOKCancel, Title:="report Date") End If If nResult = vbOK Then Call createXLdb.CkforDupes Fprocess1 = True End If End Sub Sub optSaveIndesign_Click() If Fprocess1 = True Then Fprocess2 = False If optSaveIndesign.Value = True Then Call saveIndesign.saveIndesign Fprocess2 = True End If Else MsgBox "Please check for duplicates first." End If End Sub Sub optReformatDepts_Click() If Fprocess1 = True And Fprocess2 = True Then Fprocess3 = False If optReformatDepts.Value = True Then Call ReformatDepts.ColorDivHeaders On Error Resume Next Call ReformatDepts.StatusRowHeader On Error Resume Next Call ReformatDepts.HideXtraColumns On Error Resume Next Call ReformatDepts.ReportSetup Fprocess3 = True End If Else MsgBox "Please check for duplicates and save first." End If End Sub Private Sub UserForm_Click() End Sub |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
On Error {...} Resume Next | Excel Programming | |||
On Error Resume Next ? | Excel Programming | |||
On Error Resume Next | Excel Programming | |||
On Error Resume Next | Excel Programming | |||
On Error Resume Next | Excel Programming |