Ok folks, I am creating a dynamic report generator so that I don't have to recompile the .exe everytime I create a new report. I have created a form that has aproximately 15 fields (combo boxes) that are all disabled until after the user selects a report title from the first combo box (this one is dynamically loaded from a table that holds report info). After the user selects a report title the program queries the table again and, based on a series of yes/no fields in the report table for that report, makes the rest of the combo boxes enabled or disabled. Then the user selects the values they want from the enabled combo boxes and clicks a button to get veiw the report in snapshot viewer. What actually happens behind the scene is a access report is already created and just uses the users entries as part of the where condition. (This is where the problem begins) Since there are so many posibilities for where conditions because there would be one for each report, I would like to store the where condition code in a field within the report info table. The following is the module that performs this action.
Dim dbRecap As Object
Dim strSQL As String
Dim strReportName As String
Set conData = New ADODB.Connection
Set rsData = New ADODB.Recordset
conData.Open strConn
With rsData
.CursorLocation = adUseClient
.Open "Select * FROM tblTradesReports WHERE tblTradesReports.reportDisplayName='" & strCourseName & "'", strConn, adOpenForwardOnly, adLockReadOnly, adCmdText
If .RecordCount = 1 Then
strReportName = ![ReportName] 'Gets the true access report name
strSQL = ![reportQuery] 'Gets the code for the where condition. Example- strSQL="tblCourses.courseCode='" & Trim(Left(cboSelect.Text, 9)) & "'"
End If
.Close
End With
conData.Close
Set rsData = Nothing
Set conData = Nothing
Dim objRecap As Access.Application
Set objRecap = New Access.Application
Set dbRecap = objRecap.DBEngine.OpenDatabase(strAppPath & "industry.mdb", True, True, ";PWD=" & pwd)
objRecap.OpenCurrentDatabase strAppPath & "industry.mdb"
With objRecap
.Visible = False
.DoCmd.OpenReport strReportName, acViewPreview, , strSQL
.DoCmd.OutputTo acOutputReport, "rptTempCourseRoster", ".snp", App.Path & "\report.snp"
.DoCmd.Close acReport, strReportName, acSaveNo
End With
objRecap.CloseCurrentDatabase
objRecap.Application.Quit
dbRecap.Close
Set dbRecap = Nothing
Set objRecap = Nothing
View_Report 'this opens the report.snp file
Exit Sub
HandleError:
gatherErrInfo
I am thinking that the quotes cause the problem, but when I run the program it returns nothing, but I do have the correct number of records and the proper info in both the strSQL and strReportName variables. If I cut and paste the same line that is in the strSQL variable to the code itself the report works, but if I pass it using the variable the report shows no results. Any ideas???
Dim dbRecap As Object
Dim strSQL As String
Dim strReportName As String
Set conData = New ADODB.Connection
Set rsData = New ADODB.Recordset
conData.Open strConn
With rsData
.CursorLocation = adUseClient
.Open "Select * FROM tblTradesReports WHERE tblTradesReports.reportDisplayName='" & strCourseName & "'", strConn, adOpenForwardOnly, adLockReadOnly, adCmdText
If .RecordCount = 1 Then
strReportName = ![ReportName] 'Gets the true access report name
strSQL = ![reportQuery] 'Gets the code for the where condition. Example- strSQL="tblCourses.courseCode='" & Trim(Left(cboSelect.Text, 9)) & "'"
End If
.Close
End With
conData.Close
Set rsData = Nothing
Set conData = Nothing
Dim objRecap As Access.Application
Set objRecap = New Access.Application
Set dbRecap = objRecap.DBEngine.OpenDatabase(strAppPath & "industry.mdb", True, True, ";PWD=" & pwd)
objRecap.OpenCurrentDatabase strAppPath & "industry.mdb"
With objRecap
.Visible = False
.DoCmd.OpenReport strReportName, acViewPreview, , strSQL
.DoCmd.OutputTo acOutputReport, "rptTempCourseRoster", ".snp", App.Path & "\report.snp"
.DoCmd.Close acReport, strReportName, acSaveNo
End With
objRecap.CloseCurrentDatabase
objRecap.Application.Quit
dbRecap.Close
Set dbRecap = Nothing
Set objRecap = Nothing
View_Report 'this opens the report.snp file
Exit Sub
HandleError:
gatherErrInfo
I am thinking that the quotes cause the problem, but when I run the program it returns nothing, but I do have the correct number of records and the proper info in both the strSQL and strReportName variables. If I cut and paste the same line that is in the strSQL variable to the code itself the report works, but if I pass it using the variable the report shows no results. Any ideas???