Dynamic Record Source for form

B

Brenda Love

Hello,

I have used the following code to dynamically specify the record source for
a report:

Private Sub Report_Open(Cancel As Integer)

' Create underlying recordset for report using criteria entered in

Dim intX As Integer
Dim qdf As QueryDef
Dim frm As Form


' Set database variable to current database.
Set dbsReport = CurrentDb
Set frm = Forms!DateRangePreviousCurrentYear
' Open QueryDef object.
Set qdf = dbsReport.QueryDefs("TArrivalsByRegion_Pivot")

Dim rstReport As DAO.Recordset

qdf.SQL = "EXEC TArrivalsByRegion_Pivot " &
Forms!DateRangePreviousCurrentYear!PrevYear & "," &
Forms!DateRangePreviousCurrentYear!CurrYear
qdf.ReturnsRecords = True

' Open Recordset object.

Set rstReport = qdf.OpenRecordset()
rstReport.MoveFirst


End Sub

Copied and pasted this code into the On Open event of the form, (Private Sub
Form_Open(Cancel As Integer)) but it appears that the original query in
TArrivalsByRegion_Pivot is run first, and then the new query is written into
TArrivalsByRegion_Pivot, which means that I have to run the query a second
time to obtain the correct result.

How can I resolve this?
--
---------------------------------------------
The information transmitted is intended only for the person or entity to
which it is addressed and may contain confidential, privileged and/or
private material. Any review, retransmission, dissemination or other use
of, or taking of any action in reliance upon this information by persons or
entities other than the intended recipient is prohibited. If you received
this in error, please contact the sender and delete the material from any
computer or electronic storage media; as well as destroying any physical
copies.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top