B
BSy
Hi. Any help appreciated.
I converted an Access 2007 .accdb to an .adp database. A number of the
queries converted to TVF. My attempt to convert one of them to deal with
parameters, shown under “TVF:†below, works fine when run from the Queries
Navigation Pane in Access 2007 – user is prompted for the parameters.
Upon opening a report that has its Record Source set, on the Data tab, to
[qrAll_Analysts_Report] and Record Source Qualifier set to dbo and
InputParameters set as indicated in the Report_Open event proc below,
inconsistent behavior occurs. The inconsistent behavior noticed is:
1. Upon running the application, the first call to the report yields correct
selection for the dates passed.
2. Subsequent calls, passing other dates, yields selection based upon first
set of dates passed. New dates seem to be ignored.
3. Switching the report to design view and back to report view yields
correct selection for dates passed.
Visual Basic:
Private Sub Report_Open(Cancel As Integer)
On Error GoTo Err_Report_Open
Dim sDates As String
Dim sSDate As String
Dim sEDate As String
'receive arguments
sDates = Me.OpenArgs
'parse out string token date parameters and wrap for literal string
sSDate = "#" & GetToken(sDates, 1, ";") & "#"
sEDate = "#" & GetToken(sDates, 2, ";") & "#"
'Append to pass both dates
sDates = sSDate & ", " & sEDate
'load dates parameters
Me.InputParameters = sDates
'Me.InputParameters = "#9/4/2008#, #9/5/2008#"
Exit_Report_Open:
Exit Sub
Err_Report_Open:
MsgBox "Error: " & Err.Number & " - " & Err.Description
Resume Exit_Report_Open
End Sub
TVF:
CREATE FUNCTION [dbo].[qrAll_Analysts_Report]
(@SDate datetime,
@EDate datetime)
RETURNS TABLE
AS
RETURN
(SELECT TOP 100 PERCENT
dbo.tbLookup_Employee.empFName + ' ' + dbo.tbLookup_Employee.empLName
AS Analyst
, dbo.tbPIRCatalog.Done
, dbo.tbPIRCatalog.Req
, dbo.tbPIRCatalog.Loc
, dbo.tbPIRCatalog.Requester
, dbo.tbPIRCatalog.Description
, dbo.tbLookup_Employee.empInitials + ': ' + dbo.tbLookup_Employee.empFName
+ ' ' + dbo.tbLookup_Employee.empLName AS AnalystName
, dbo.tbLookup_Employee.Hide
FROM
dbo.tbLookup_Employee INNER JOIN
dbo.tbPIRCatalog ON
dbo.tbLookup_Employee.ID_Emp = dbo.tbPIRCatalog.ID_Emp_fk
WHERE
(dbo.tbLookup_Employee.Hide = 0)
AND
(dbo.tbPIRCatalog.Done BETWEEN @SDate AND @EDate)
ORDER BY Analyst, dbo.tbPIRCatalog.Done )
I converted an Access 2007 .accdb to an .adp database. A number of the
queries converted to TVF. My attempt to convert one of them to deal with
parameters, shown under “TVF:†below, works fine when run from the Queries
Navigation Pane in Access 2007 – user is prompted for the parameters.
Upon opening a report that has its Record Source set, on the Data tab, to
[qrAll_Analysts_Report] and Record Source Qualifier set to dbo and
InputParameters set as indicated in the Report_Open event proc below,
inconsistent behavior occurs. The inconsistent behavior noticed is:
1. Upon running the application, the first call to the report yields correct
selection for the dates passed.
2. Subsequent calls, passing other dates, yields selection based upon first
set of dates passed. New dates seem to be ignored.
3. Switching the report to design view and back to report view yields
correct selection for dates passed.
Visual Basic:
Private Sub Report_Open(Cancel As Integer)
On Error GoTo Err_Report_Open
Dim sDates As String
Dim sSDate As String
Dim sEDate As String
'receive arguments
sDates = Me.OpenArgs
'parse out string token date parameters and wrap for literal string
sSDate = "#" & GetToken(sDates, 1, ";") & "#"
sEDate = "#" & GetToken(sDates, 2, ";") & "#"
'Append to pass both dates
sDates = sSDate & ", " & sEDate
'load dates parameters
Me.InputParameters = sDates
'Me.InputParameters = "#9/4/2008#, #9/5/2008#"
Exit_Report_Open:
Exit Sub
Err_Report_Open:
MsgBox "Error: " & Err.Number & " - " & Err.Description
Resume Exit_Report_Open
End Sub
TVF:
CREATE FUNCTION [dbo].[qrAll_Analysts_Report]
(@SDate datetime,
@EDate datetime)
RETURNS TABLE
AS
RETURN
(SELECT TOP 100 PERCENT
dbo.tbLookup_Employee.empFName + ' ' + dbo.tbLookup_Employee.empLName
AS Analyst
, dbo.tbPIRCatalog.Done
, dbo.tbPIRCatalog.Req
, dbo.tbPIRCatalog.Loc
, dbo.tbPIRCatalog.Requester
, dbo.tbPIRCatalog.Description
, dbo.tbLookup_Employee.empInitials + ': ' + dbo.tbLookup_Employee.empFName
+ ' ' + dbo.tbLookup_Employee.empLName AS AnalystName
, dbo.tbLookup_Employee.Hide
FROM
dbo.tbLookup_Employee INNER JOIN
dbo.tbPIRCatalog ON
dbo.tbLookup_Employee.ID_Emp = dbo.tbPIRCatalog.ID_Emp_fk
WHERE
(dbo.tbLookup_Employee.Hide = 0)
AND
(dbo.tbPIRCatalog.Done BETWEEN @SDate AND @EDate)
ORDER BY Analyst, dbo.tbPIRCatalog.Done )