Open Filtered Report in a subreport using sourceObject Property (1 Viewer)

Usmalik

New member
Local time
Today, 10:19
Joined
Sep 18, 2022
Messages
3
Hi im new here and i have a problem. I have a form "MainForm" which have 3 buttons (MasterListBtn, TransactionBtn, HistoryBtn) and a subform/Subreport (SubFormMain). For MasterListBtn, SourceObject is "MasterlListForm". For TransactionBtn, sourceObject is "TransactionForm" and For HistoryBtn, sourceObject is "HistoryForm". Upto here it is fine, working good, Now In SearchForm i have These Controls (ItemNameCb, ItemSNoTb and SearchBtn).
I want to generate a Report based on ItemNameCb, and ItemSNoTb values and i want to open that Report in SubForm by Changing SourceObject = "Report.HistoryReport"
Private Sub SearchBtn_Click()
[Forms]!MainForm]![SubFormMain].[SourceObject] = "Report.HistoryReport"
End Sub

OnLoad Event of HistoryReport
Private Sub HistoryReport_Load()
[Forms]![MainForm]![SubFormMain].[Form].RecordSource= "Select * from TransactionTable Where ItemName = ' " & [Forms]![MainForm]![SubFormMain].[Form]![ItemNameCb] & " ' and ItemSNo = ' " & [Forms]![MainForm]![SubFormMain].[Form]![ItemSNoTb] & " ' "
End Sub

I tried a lot Report opens in SubFormMain but the report Shows nothing

Any Help?
 
Last edited:

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 22:19
Joined
Oct 29, 2018
Messages
21,498
Hi. Welcome to AWF!

You might also need to either clear or set the Linked Master and Linked Child Fields.
 

Usmalik

New member
Local time
Today, 10:19
Joined
Sep 18, 2022
Messages
3
Hi. Welcome to AWF!

You might also need to either clear or set the Linked Master and Linked Child Fields.
I am sorry to say, im little bit new to access, Can you explain what do u mean by Linked Master And Linked Child fields?
When i tried using Docmd.OpenReport "HistoryReport", , (WhereCondition) it works fine, but i dont want to open report in new window, i want to open report in SubForm
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 22:19
Joined
Oct 29, 2018
Messages
21,498
I am sorry to say, im little bit new to access, Can you explain what do u mean by Linked Master And Linked Child fields?
When i tried using Docmd.OpenReport "HistoryReport", , (WhereCondition) it works fine, but i dont want to open report in new window, i want to open report in SubForm
How did you originally add the subform control onto the form? If you look at its properties, it probably has something assigned in the Linked Master and Linked Child Fields. You either assigned them manually, or the Wizard did it for you. Since you're assigning a Report in its place, after creating to contain forms, then perhaps those settings are what's making the report show up empty.
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 22:19
Joined
Oct 29, 2018
Messages
21,498
I have assigned Them manually by using VBA
Okay, so what I was saying is maybe assign the correct one for the report or simply remove them just to see if you get any results back.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 13:19
Joined
May 7, 2009
Messages
19,246
you use the Report's Open event (not the Load event):

private sub form_open(cancel as integer)
me.recordsource = "Select * from TransactionTable Where ItemName = '" & [Forms]![MainForm]![SubFormMain].[Form]![ItemNameCb] & "' and ItemSNo = '" & [Forms]![MainForm]![SubFormMain].[Form]![ItemSNoTb] & "'"
end sub
 

Users who are viewing this thread

Top Bottom