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