command buttons to preview or print report

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

(I'm reposting as received no reply. original post in Access Database Forms
6/20 with title preview only 1 report)

I'm working in Access 2000. I have a form with 2 different list boxes of
reports which comes from a ReportName table having user friendly names,
actual report name and code to determine which type of report.

I'm trying to program command buttons on the form - 1 button to preview
report and 1 button to print. This was copied and adapted from the Northwind
DB sample in Access. I don't want to use AfterUpdate property for list box
because I want
the user to have the choice of previewing or printing the selected report.

problem #1 - Right now I can select a report from both list. I only want
user to be able to select report from 1 list at a time.

problem #2 - I can't get the command buttons to carry out the task after a
report is selected. Below is the code I've attempted for Preview which I
can adapt for Print using acViewNormal.
*****************************
Private Sub cmdPreview_Click()
' Preview selected report
' adapted from Northwind Database sample from Microsoft

Dim rptChoice As String
rptChoice = "Me.[ctlAgentReports]" Or "Me.[ctlCallReports]"

If IsNull(Me.ctlCallReports) Or IsNull(Me.ctlAgentReports) Then
MsgBox "Please select a report", vbExclamation, "Problem running report"
Else
DoCmd.OpenReport rptChoice, acViewPreview
End If
End Sub
****************************************
I'm getting type mismatch related to my rptChoice variable. I'm sure the
"or" is throwing if off somehow. I've also tried code without rptChoice
variable and just
used DoCmd.PrintReport Me![ctlCallReports], acViewPreview but get message
"method or data member not found". When I search VBA Help I've discovered
Print Method can only be used with the OnPrint Property and PrintReport
doesn't seem to be valid.

Thanks for any input,
Marcia
 
This line of code will not work:

rptChoice = "Me.[ctlAgentReports]" Or "Me.[ctlCallReports]"

You can only assign one value to a variable, but you can do it based on a
condition. You have to know which you want.

Also, in this line, rptChoice is the name of the report, not the name of a
list box:

DoCmd.OpenReport rptChoice, acViewPreview

The above is causing problem 2

Also, This line will always return False unless you have selected a report
from each list (which in not likely). This is causing Problem 1.

If IsNull(Me.ctlCallReports) Or IsNull(Me.ctlAgentReports)

I think this is what you are trying to do.

Private Sub cmdPreview_Click()
Dim rptChoice As String

If IsNull(Me.ctlCallReports.Value) And IsNull(Me.ctlAgentReports.Value)
Then
MsgBox "Please select a report", vbExclamation, "Problem running
report"
Else
rptChoice = IIf(IsNull(Me.ctlCallReport.Value),
Me.ctlAgentReport.Value, _
& Me.ctlCallReport.Value)
DoCmd.OpenReport rptChoice, acViewPreview
End If
End Sub

This will not allow you to select a report from both columns. If the user
makes a selection in each column, then he will get only the Call Report.

Hope this helps.

Office User said:
(I'm reposting as received no reply. original post in Access Database Forms
6/20 with title preview only 1 report)

I'm working in Access 2000. I have a form with 2 different list boxes of
reports which comes from a ReportName table having user friendly names,
actual report name and code to determine which type of report.

I'm trying to program command buttons on the form - 1 button to preview
report and 1 button to print. This was copied and adapted from the Northwind
DB sample in Access. I don't want to use AfterUpdate property for list box
because I want
the user to have the choice of previewing or printing the selected report.

problem #1 - Right now I can select a report from both list. I only want
user to be able to select report from 1 list at a time.

problem #2 - I can't get the command buttons to carry out the task after a
report is selected. Below is the code I've attempted for Preview which I
can adapt for Print using acViewNormal.
*****************************
Private Sub cmdPreview_Click()
' Preview selected report
' adapted from Northwind Database sample from Microsoft

Dim rptChoice As String
rptChoice = "Me.[ctlAgentReports]" Or "Me.[ctlCallReports]"

If IsNull(Me.ctlCallReports) Or IsNull(Me.ctlAgentReports) Then
MsgBox "Please select a report", vbExclamation, "Problem running report"
Else
DoCmd.OpenReport rptChoice, acViewPreview
End If
End Sub
****************************************
I'm getting type mismatch related to my rptChoice variable. I'm sure the
"or" is throwing if off somehow. I've also tried code without rptChoice
variable and just
used DoCmd.PrintReport Me![ctlCallReports], acViewPreview but get message
"method or data member not found". When I search VBA Help I've discovered
Print Method can only be used with the OnPrint Property and PrintReport
doesn't seem to be valid.

Thanks for any input,
Marcia
 
Thanks, I'll give the IIf code a try when I get back to work. I'm thinking
I'll need to add something like an If, Then Else though because the user
could actually choose a report from ctlCallReports list OR from
ctlAgentReports list. The list are just 2 different KINDS of reports not
dependent on each other.

Thanks,
Marcia

Klatuu said:
This line of code will not work:

rptChoice = "Me.[ctlAgentReports]" Or "Me.[ctlCallReports]"

You can only assign one value to a variable, but you can do it based on a
condition. You have to know which you want.

Also, in this line, rptChoice is the name of the report, not the name of a
list box:

DoCmd.OpenReport rptChoice, acViewPreview

The above is causing problem 2

Also, This line will always return False unless you have selected a report
from each list (which in not likely). This is causing Problem 1.

If IsNull(Me.ctlCallReports) Or IsNull(Me.ctlAgentReports)

I think this is what you are trying to do.

Private Sub cmdPreview_Click()
Dim rptChoice As String

If IsNull(Me.ctlCallReports.Value) And IsNull(Me.ctlAgentReports.Value)
Then
MsgBox "Please select a report", vbExclamation, "Problem running
report"
Else
rptChoice = IIf(IsNull(Me.ctlCallReport.Value),
Me.ctlAgentReport.Value, _
& Me.ctlCallReport.Value)
DoCmd.OpenReport rptChoice, acViewPreview
End If
End Sub

This will not allow you to select a report from both columns. If the user
makes a selection in each column, then he will get only the Call Report.

Hope this helps.

Office User said:
(I'm reposting as received no reply. original post in Access Database Forms
6/20 with title preview only 1 report)

I'm working in Access 2000. I have a form with 2 different list boxes of
reports which comes from a ReportName table having user friendly names,
actual report name and code to determine which type of report.

I'm trying to program command buttons on the form - 1 button to preview
report and 1 button to print. This was copied and adapted from the Northwind
DB sample in Access. I don't want to use AfterUpdate property for list box
because I want
the user to have the choice of previewing or printing the selected report.

problem #1 - Right now I can select a report from both list. I only want
user to be able to select report from 1 list at a time.

problem #2 - I can't get the command buttons to carry out the task after a
report is selected. Below is the code I've attempted for Preview which I
can adapt for Print using acViewNormal.
*****************************
Private Sub cmdPreview_Click()
' Preview selected report
' adapted from Northwind Database sample from Microsoft

Dim rptChoice As String
rptChoice = "Me.[ctlAgentReports]" Or "Me.[ctlCallReports]"

If IsNull(Me.ctlCallReports) Or IsNull(Me.ctlAgentReports) Then
MsgBox "Please select a report", vbExclamation, "Problem running report"
Else
DoCmd.OpenReport rptChoice, acViewPreview
End If
End Sub
****************************************
I'm getting type mismatch related to my rptChoice variable. I'm sure the
"or" is throwing if off somehow. I've also tried code without rptChoice
variable and just
used DoCmd.PrintReport Me![ctlCallReports], acViewPreview but get message
"method or data member not found". When I search VBA Help I've discovered
Print Method can only be used with the OnPrint Property and PrintReport
doesn't seem to be valid.

Thanks for any input,
Marcia
 
Back
Top