G
GLepage
I am trying to use a recordset as a reports data source, in the report
open event I have the line:
Me.RecordSource = rstUserReport.Name
In a standard module:
Option Compare Database
'***********************************************
'Developed & Written by Gene Lepage
'Alstom - Power
'Boliers NAM
'All Rights Reserved.
'
'Adapted from Code Courtesy
'of Andy Baron
'
'In: Dates and up to 3 WHERE statements
'Out: Recordsource for rptUserReport
'
'Created: 4/16/2007
'
'Modified:
'***********************************************
'Declare public recordset variable
Public rstUserReport As DAO.Recordset
'Supply the report with a recordset object based on SQL statment with
user selected cirteria
Public Sub RunUserReport()
Dim strTerm1 As String, strTerm2 As String, strTerm3 As String
Dim dtStart As Date, dtEnd As Date
Dim strSQL As String, strWhere As String, lngCount As Long
'Get the start and end dates for the report
dtStart = Forms![frmSelectRptsAdvanced].[txtStartDate]
dtEnd = Forms![frmSelectRptsAdvanced].[txtEndDate]
'Get the user selected cirteria for the report
strTerm1 = Forms![frmSelectRptsAdvanced].[txtResult1]
strTerm2 = Forms![frmSelectRptsAdvanced].[txtResult2]
strTerm3 = Forms![frmSelectRptsAdvanced].[txtResult3]
'Determine how many field the user selected for the report
lngCount = 0
If strTerm1 = "" Then
lngCount = 0
Else
lngCount = 1
End If
If strTerm2 = "" Then
lngCount = lngCount
Else
lngCount = lngCount + 1
End If
If strTerm3 = "" Then
lngCount = lngCount
Else
lngCount = lngCount + 1
End If
Select Case lngCount
Case Is = 1 'One field used
strWhere = "WHERE (" & strTerm1
Case Is = 2 'Two fields used
strWhere = "WHERE (" & strTerm1 & "AND " & strTerm2
Case Is = 3 'Three fields used
strWhere = "WHERE (" & strTerm1 & "AND " & strTerm2 & "AND
" & strTerm3
Case Else
Exit Sub
End Select
'Build SQL statement to use as the recordset object
strSQL = "SELECT [PowerSolve All Issues].[Contract Name],
[PowerSolve All Issues].[Ref #], [PowerSolve All Issues].[Issue
Title], [PowerSolve All Issues].[Orig/PM Est], [PowerSolve All Issues].
[Actual Cost], [PowerSolve All Issues].Responsibility, [PowerSolve All
Issues].Status, [PowerSolve All Issues].[Supplier Name], [PowerSolve
All Issues].[WO #], [PowerSolve All Issues].Created, [PowerSolve All
Issues].[Disposition Type], [PowerSolve All Issues].[Problem Desc],
[PowerSolve All Issues].[Technical Resolution], [PowerSolve All
Issues].[Commercial Resolution], [PowerSolve All Issues].[Ref Plant],
[PowerSolve All Issues].[Request Type] "
strSQL = strSQL + "FROM [PowerSolve All Issues] "
strSQL = strSQL + strWhere
strSQL = strSQL + "AND (([PowerSolve All Issues].[Created])
BETWEEN #" & dtStart & "# AND #" & dtEnd & "#));"
'Open the recordset
Set rstUserReport = CurrentDb.OpenRecordset(strSQL)
'Open the report
DoCmd.OpenReport "rptUserReport", acViewPreview
'Reset counter and destroy objects
lngCount = 0
rstUserReport.Close
Set rstUserReport = Nothing
End Sub
I can move through the recordset in code (approx 345 records returned
by this SQL) but when the report tyies to open I get the error
message:
Run-Time Error 2580 - The recordsource specified on this form or
report does not exist.
If I debug.print the rstUserReport.Name I get just a small part of the
SQL statement.
What am I doing wrong - please be gentle it's my first post.
open event I have the line:
Me.RecordSource = rstUserReport.Name
In a standard module:
Option Compare Database
'***********************************************
'Developed & Written by Gene Lepage
'Alstom - Power
'Boliers NAM
'All Rights Reserved.
'
'Adapted from Code Courtesy
'of Andy Baron
'
'In: Dates and up to 3 WHERE statements
'Out: Recordsource for rptUserReport
'
'Created: 4/16/2007
'
'Modified:
'***********************************************
'Declare public recordset variable
Public rstUserReport As DAO.Recordset
'Supply the report with a recordset object based on SQL statment with
user selected cirteria
Public Sub RunUserReport()
Dim strTerm1 As String, strTerm2 As String, strTerm3 As String
Dim dtStart As Date, dtEnd As Date
Dim strSQL As String, strWhere As String, lngCount As Long
'Get the start and end dates for the report
dtStart = Forms![frmSelectRptsAdvanced].[txtStartDate]
dtEnd = Forms![frmSelectRptsAdvanced].[txtEndDate]
'Get the user selected cirteria for the report
strTerm1 = Forms![frmSelectRptsAdvanced].[txtResult1]
strTerm2 = Forms![frmSelectRptsAdvanced].[txtResult2]
strTerm3 = Forms![frmSelectRptsAdvanced].[txtResult3]
'Determine how many field the user selected for the report
lngCount = 0
If strTerm1 = "" Then
lngCount = 0
Else
lngCount = 1
End If
If strTerm2 = "" Then
lngCount = lngCount
Else
lngCount = lngCount + 1
End If
If strTerm3 = "" Then
lngCount = lngCount
Else
lngCount = lngCount + 1
End If
Select Case lngCount
Case Is = 1 'One field used
strWhere = "WHERE (" & strTerm1
Case Is = 2 'Two fields used
strWhere = "WHERE (" & strTerm1 & "AND " & strTerm2
Case Is = 3 'Three fields used
strWhere = "WHERE (" & strTerm1 & "AND " & strTerm2 & "AND
" & strTerm3
Case Else
Exit Sub
End Select
'Build SQL statement to use as the recordset object
strSQL = "SELECT [PowerSolve All Issues].[Contract Name],
[PowerSolve All Issues].[Ref #], [PowerSolve All Issues].[Issue
Title], [PowerSolve All Issues].[Orig/PM Est], [PowerSolve All Issues].
[Actual Cost], [PowerSolve All Issues].Responsibility, [PowerSolve All
Issues].Status, [PowerSolve All Issues].[Supplier Name], [PowerSolve
All Issues].[WO #], [PowerSolve All Issues].Created, [PowerSolve All
Issues].[Disposition Type], [PowerSolve All Issues].[Problem Desc],
[PowerSolve All Issues].[Technical Resolution], [PowerSolve All
Issues].[Commercial Resolution], [PowerSolve All Issues].[Ref Plant],
[PowerSolve All Issues].[Request Type] "
strSQL = strSQL + "FROM [PowerSolve All Issues] "
strSQL = strSQL + strWhere
strSQL = strSQL + "AND (([PowerSolve All Issues].[Created])
BETWEEN #" & dtStart & "# AND #" & dtEnd & "#));"
'Open the recordset
Set rstUserReport = CurrentDb.OpenRecordset(strSQL)
'Open the report
DoCmd.OpenReport "rptUserReport", acViewPreview
'Reset counter and destroy objects
lngCount = 0
rstUserReport.Close
Set rstUserReport = Nothing
End Sub
I can move through the recordset in code (approx 345 records returned
by this SQL) but when the report tyies to open I get the error
message:
Run-Time Error 2580 - The recordsource specified on this form or
report does not exist.
If I debug.print the rstUserReport.Name I get just a small part of the
SQL statement.
What am I doing wrong - please be gentle it's my first post.