Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a report that displays another form's recordsource. When I add some record on this form and click for report, this records is not being displayed. How can I achieve displaying what is on screen - allways ? Here is my simple code for report:

Private Sub cmdOpenReport_Click()

   DoCmd.OpenReport "MyReport", acViewReport

End Sub

Private Sub Report_Open(Cancel As Integer)

   Me.RecordSource = Forms![MyForm].Form.RecordSource

End Sub
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
175 views
Welcome To Ask or Share your Answers For Others

1 Answer

You need to close the Report before re-opening it and save the new record.

In the click event of your Open Report button insert the following:

Private Sub OpenReport_Click()

    DoCmd.RunCommand acCmdSaveRecord
    DoCmd.Close acReport, "Test1", acSaveYes
    DoCmd.OpenReport "Test1", acViewPreview

End Sub

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...