Open Report 2 if Report 1 is empty

mercredi 25 mars 2015

Hi all,



In a Dialog Box there are several buttons that open Reports (in On click Event, open Report, close Dialog Box). One of this reports check new data in one Unit during the last 30 days. If it is empty, No data Event runs:



MsgBox "During the last 30 days...there are no new data in the Unit " & [Forms]![Nameform]![NameUnit]

Cancel = True



But if the user needs a proof that he or she really has checked today for new records in the Unit, I would like to change the MsgBox:



"During the last 30 days there are no new data in the Unit " & [Forms]![Nameform]![NameUnit] & ". Would you like to print this information? (Y/N)"



..giving the chance to print or not a second Report, that is basically like the first, but changing the fields for a message similar to that one in the message box.



I tried in the same No data event, but it does not work (I was quite sure...):



Private Sub Report_NoData(Cancel As Integer)

Dim Message As String

Dim Box As String



Message = "During the last 30 days there are no new data in the Unit " & [Forms]![NameForm]![NameUnit] & ". Would you like to print this information?"

Box = MsgBox(Message, 4, "Unit")



If Box = vbOK Then

DoCmd.OpenReport "NameReport2", acViewPreview, "", "", acNormal

DoCmd.Close acForm, "FrmDialogBox"



Else



Cancel = True

End If

End Sub.



So...the idea is: If Report 1 is not empty, it will appear; if empty, No Data Event runs and check the MsgBox: if yes, Report 2 appears.



I thought...maybe in the On click Event in the button, something like: IF Report 1 has No Data THEN open Report 2 ELSE Open report 1.



What do you think?



Many thanks in advance!

Open Report 2 if Report 1 is empty

0 commentaires:

Enregistrer un commentaire

Labels