Display sub Sub Report based on response to message box

andy1968

Registered User.
Local time
Yesterday, 19:24
Joined
May 9, 2018
Messages
131
I would like to give the user the option to display a sub report using a message box.


This is the code I have tried, unsuccessfully:


Private Sub cmdPrint_Click()
Dim res As Integer
DoCmd.RunCommand acCmdSaveRecord

If MsgBox("Do you want to include missing criteria on the reply to contractor?", _
VbMsgBoxStyle.vbYesNo Or VbMsgBoxStyle.vbQuestion Or VbMsgBoxStyle.vbDefaultButton2, _
"Include Missing Criteria?") = vbYes Then
DoCmd.OpenReport "rptSubmittalReplyWhere", acViewPreview, ,
Me.rptMissingCritieriaWhere.Visible = True
Else
DoCmd.OpenReport "rptSubmittalReplyWhere", acViewPreview, ,
End If
End Sub


I get an error saying "rptMissingCritieriaWhere" is not found.
 
Me refers to the object containing the code, so this line would have to be in the report:

Me.rptMissingCritieriaWhere.Visible = True

I'd probably pass something in OpenArgs and have that code in the load event of the report, testing the OpenArgs value.
 
Thanks Paul.


I'll play around with that, though sending openargs is not something I know well.


I'll do my best and let you know how it works.


Andy
 
No problem Andy, post back if you get stuck.
 
Got it!


Works like a charm.


Dim res As Integer
DoCmd.RunCommand acCmdSaveRecord
' This message box will allow the user to show the critieria that is missing, if they want
res = MsgBox("Do you want to include missing criteria on the reply to contractor?", _
VbMsgBoxStyle.vbYesNo Or VbMsgBoxStyle.vbQuestion Or VbMsgBoxStyle.vbDefaultButton2, _
"Include Missing Criteria?")

DoCmd.OpenReport "rptSubmittalReplyWhere", acViewPreview, , "[SerialNumber]=" & Me![cmbSubmittal] & "And [Number]='" & Me![txtNo] & "'", , res

And on the report:



Private Sub Report_Open(Cancel As Integer)
If Me.OpenArgs() = vbYes Then
Me.rptMissingCritieriaWhere.Visible = True
Else
Me.rptMissingCritieriaWhere.Visible = False
End If
End Sub
 

Users who are viewing this thread

Back
Top Bottom