samerickson89
New Member
- Joined
- Jun 13, 2019
- Messages
- 38
I've got a subroutine 'Print_Report' that calls another subroutine 'Check_Fields' and basically, if certain cells are empty then 'Check_Fields' exits the subroutine, but 'Print_Report' continues to run. How can I make one subroutine exit based on something in another subroutine? I tried using end, but I also want the ability to cancel the 'BeforePrint' event if need be. Here's my code so far:
Code:
Sub Print_Report()
Call modCheck.Check_Fields
Dim Today As String
Dim OutName As String
Today = Format(Date, "yyyymmdd")
OutName = "FCAD_ECR_" & Today
ActiveSheet.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=ActiveWorkbook.Path & "\Filled Out ECR's\" & OutName, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=False, _
IgnorePrintAreas:=False, _
to:=1, _
OpenAfterPublish:=True
End Sub
Code:
Sub Check_Fields()
If Range("E4").Value = "" Then
MsgBox "Field 'Requested by' is mandatory"
Exit Sub
End If
If Range("E11").Value = "" Then
MsgBox "Field 'Reason for change' is mandatory"
Exit Sub
End If
If Range("E26").Value = "" Then
MsgBox "Field 'Where was the issue identified?' is mandatory"
Exit Sub
End If
End Sub