Display sub Sub Report based on response to message box (1 Viewer)

andy1968

Registered User.
Local time
Today, 05:30
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.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 05:30
Joined
Aug 30, 2003
Messages
36,125
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.
 

andy1968

Registered User.
Local time
Today, 05:30
Joined
May 9, 2018
Messages
131
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
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 05:30
Joined
Aug 30, 2003
Messages
36,125
No problem Andy, post back if you get stuck.
 

andy1968

Registered User.
Local time
Today, 05:30
Joined
May 9, 2018
Messages
131
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
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 05:30
Joined
Aug 30, 2003
Messages
36,125
Happy to help!
 

Users who are viewing this thread

Top Bottom