Hi (1 Viewer)

Niroshana

New member
Local time
Tomorrow, 03:16
Joined
Jul 10, 2020
Messages
8
hi
I want to change the record source (SQL) of sub report by VBA code when open the main report. Please help me to build the code.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 05:46
Joined
May 7, 2009
Messages
19,245
what do you mean?
you can have a Master/Child Link Fields in your subreport, and only show
related records from the record of Main report.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 16:46
Joined
Feb 28, 2001
Messages
27,192
Note that if you change the .Recordsource of a report, if the field names in the source don't match the field names used in building the report, you just broke the report.
 

Niroshana

New member
Local time
Tomorrow, 03:16
Joined
Jul 10, 2020
Messages
8
My code is as follows, but there is an error in the code, Please help me to resolve the issue.


Private Sub Command33_Click()


Dim Dbs As DAO.Database
Dim Rst As DAO.Recordset

Set Dbs = CurrentDb
Set Rst = Dbs.OpenRecordset("Select * from [ACTIVE SERVICE ORDERS EXP EMAIL] ")

Rst.MoveFirst

Do While Not Rst.EOF


Report_LETTEREMAIL.LETTERSUB.Report.RecordSource = "Select * ACTSEVEMAILQ WHERE SID=" & Rst!SID

DoCmd.OpenReport "LETTEREMAIL", acViewPreview, , , acWindowNormal

Rst.MoveNext

Loop


End Sub
 
Last edited:

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 05:46
Joined
May 7, 2009
Messages
19,245
you'll end up with Endless Loop there, you are Missing Rst.MoveNext.
it does qualify for Master/Child Link Fields on your subReport.
can you upload your db or share it on your dropbox/onedrive?
 

Niroshana

New member
Local time
Tomorrow, 03:16
Joined
Jul 10, 2020
Messages
8
Thanks you for your reply

There is no Master/Child Link Fields. When move the record through the loop, updating only subReport data.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 05:46
Joined
May 7, 2009
Messages
19,245
you add Master/Child Link Fields.
so you do not use Recordset at all.
see this demo and open LETTEREMAIL report in Print Preview.
 

Attachments

  • ActiveServiceOrders.accdb
    1 MB · Views: 105

Users who are viewing this thread

Top Bottom