rushitshah
Registered User.
- Local time
- Today, 11:40
- Joined
- Jul 27, 2005
- Messages
- 19
Hello.
I need help regaring report generation with VBA coding.
I want to use two different tables for report generation on If Else statement.
These two tables are basically queries run for different parameters and products. SO I am doing this. It works correctly and generates the query tables, asks for input from user to save report, But the report is empty. It does not print all the record sets from the corrosponding table to the report.
What I am doing wrong?
______________________________________________
Dim rpt As Report
Dim strReportName As String
If IsNull(Me.Product) = True Or Me.Product = "" Then
strSQL = "SELECT t.* " & _ 'this query will generate table
"INTO [" & Me.Parameters & "] " & _
"FROM [" & Me.PCycle & "] t " & _
"WHERE t.parm_nm = '" & Me.Parameters & "';"
DoCmd.RunSQL strSQL
strReportName = InputBox("Enter the report name", "Report Name")
Set rpt = CreateReport
rpt.RecordSource = "SELECT p.* FROM [" & Me.Parameters & "] p"
DoCmd.Save , strReportName
DoCmd.Close , , acSaveYes
DoCmd.OpenReport strReportName, acViewPreview
ElseIf IsNull(Me.Parameters) = True Or Me.Parameters = "" Then
strSQL = "SELECT t.* " & _
"INTO [" & Me.Product & "] " & _
"FROM [" & Me.PCycle & "] t " & _
"WHERE t.infr_itm_nm = '" & Me.Product & "';"
DoCmd.RunSQL strSQL
strReportName = InputBox("Enter the report name", "Report Name")
Set rpt = CreateReport
rpt.RecordSource = "SELECT p.* FROM [" & Me.Product & "] p"
DoCmd.Save , strReportName
DoCmd.Close , , acSaveYes
DoCmd.OpenReport strReportName, acViewPreview
End If
I need help regaring report generation with VBA coding.
I want to use two different tables for report generation on If Else statement.
These two tables are basically queries run for different parameters and products. SO I am doing this. It works correctly and generates the query tables, asks for input from user to save report, But the report is empty. It does not print all the record sets from the corrosponding table to the report.
What I am doing wrong?
______________________________________________
Dim rpt As Report
Dim strReportName As String
If IsNull(Me.Product) = True Or Me.Product = "" Then
strSQL = "SELECT t.* " & _ 'this query will generate table
"INTO [" & Me.Parameters & "] " & _
"FROM [" & Me.PCycle & "] t " & _
"WHERE t.parm_nm = '" & Me.Parameters & "';"
DoCmd.RunSQL strSQL
strReportName = InputBox("Enter the report name", "Report Name")
Set rpt = CreateReport
rpt.RecordSource = "SELECT p.* FROM [" & Me.Parameters & "] p"
DoCmd.Save , strReportName
DoCmd.Close , , acSaveYes
DoCmd.OpenReport strReportName, acViewPreview
ElseIf IsNull(Me.Parameters) = True Or Me.Parameters = "" Then
strSQL = "SELECT t.* " & _
"INTO [" & Me.Product & "] " & _
"FROM [" & Me.PCycle & "] t " & _
"WHERE t.infr_itm_nm = '" & Me.Product & "';"
DoCmd.RunSQL strSQL
strReportName = InputBox("Enter the report name", "Report Name")
Set rpt = CreateReport
rpt.RecordSource = "SELECT p.* FROM [" & Me.Product & "] p"
DoCmd.Save , strReportName
DoCmd.Close , , acSaveYes
DoCmd.OpenReport strReportName, acViewPreview
End If