473,396 Members | 2,093 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Reusable report with a modifiable rowsource property and or code ?

How do I call a reusable report with a modifiable Rowsource property
and or code ?
Like in the following case where the table name will change any
following day ?
I am using Access 2003.

Private Sub Top25_Click()
Dim strSQL As String
strTblName = "tblNew_" & Format(Date, "ddmmmyyyy")
strSQL = "SELECT TOP 25 tblOld.Fname, tblOld.Lname INTO " &
strTblName & " FROM tblOld"
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL
DoCmd.SetWarnings True
' How to I call the report with the variable Rowsource strTblName
from here ?
......
End Sub

Thank you for your Help,
Wayne

Jan 2 '07 #1
3 2105
u473 wrote:
>How do I call a reusable report with a modifiable Rowsource property
and or code ?
Like in the following case where the table name will change any
following day ?
I am using Access 2003.

Private Sub Top25_Click()
Dim strSQL As String
strTblName = "tblNew_" & Format(Date, "ddmmmyyyy")
strSQL = "SELECT TOP 25 tblOld.Fname, tblOld.Lname INTO " &
strTblName & " FROM tblOld"
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL
DoCmd.SetWarnings True
' How to I call the report with the variable Rowsource strTblName
from here ?
......
End Sub

The only reliable place at run time that you can set a
report's RecordSource is in the report's Open event.

I see no reason in your post for the use of a make table
query. Why not just use the select part in the report? If
you are using the make table as some kind of archive, I
suggest that it would be better to use a date field in the
original table and execute an Update query to record the
report date.

You can use the OpenReport method's OpenArgs argument to
pass the SQL statement to the report:

Private Sub Top25_Click()
Dim strSQL As String
strSQL = "SELECT TOP 25 Fname, Lname FROM tblOld"
DoCmd.OpenReport "reportname", OpenArgs:= strSQL

In the report's Open event procedure:

If Not IsNull(Me.OpenArgs) Then
Me.RecordSource = Me.OpenArgs
End If

--
Marsh
Jan 2 '07 #2

Thank you, you made my day.
I wanted to grab some VBA /SQL concepts and I made some progress
thanks to you.
But, in the design phase of the report, am I not obliged to enter
something for the Rowsource Property, or will will it be satisfied
from the On Open code ?

Jan 6 '07 #3
u473 wrote:
>Thank you, you made my day.
I wanted to grab some VBA /SQL concepts and I made some progress
thanks to you.
But, in the design phase of the report, am I not obliged to enter
something for the Rowsource Property, or will will it be satisfied
from the On Open code ?

RecordSource, not RowSource.

No, you can leave the RecordSource property empty at design
time. If you have code that refers to fields in the record
source, use their corresponding bound controls instead.
Sometimes it is easier to design and test report with its
RecordSource set, and remove the RecordSource after
everything else is squared away. OTOH, as long as the field
list is always the same, it is no big deal to leave the
RecordSource in and overwrite it in the Open event
procedure.

--
Marsh
Jan 6 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Irena | last post by:
Hi all again, Maybe, I'd better try to do this: How can it programmatically get/return the "Row source" or Rowsource property of a generic Table in a generic Access 2K database??? I found...
8
by: | last post by:
hi, i have a form on which a user can choose specific criteria such as dates etc, in order to filter the report that is called from the form. i do this by using the Where section of the...
3
by: ML | last post by:
I have used Allen Brown's technique for filling a listbox on a form with the names of files in a certain disc folder. It works well. I am now giving the user the option to print the form...
2
by: lgeastwood | last post by:
I have a Report with a listbox that I need to populate with a rowsource type = valuelist. The valuelist for each record is a saved SQL string complete with commas On my form I can set the...
5
by: jonosborne | last post by:
Hi, i have managed to filter a report based on selections made in a list box but am totally confused with a message box that appears everytime i run my report. Let me explain (i apologise for...
6
by: Dave | last post by:
On my form I have combo boxes. These combo boxes, after updating them, populate respective listboxes that are located below the combo boxes on the same form. I am trying to use a "generate...
2
by: Simon | last post by:
Dear reader, The syntax for the VBA code to change the RowSource of a Form is: Forms!FormName..RowSource = "TableOrQueryName"
1
by: ikuyasu | last post by:
Hi, I am trying to create a report that takes a value from the field on a table as a group category. But The value on the report takes an id number (auto increment, and the first column)...
10
by: Snoopy33 | last post by:
I have a DB that I developed on access XP (2002) and deployed over a year ago. No one has had problems printing any of the reports within the DB until we started loading 2007 on new computers. ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.