Question Printing a selection from a combo list

Tumby

Registered User.
Local time
Today, 13:58
Joined
Jan 12, 2009
Messages
64
I have created a combo list for Reports in my db but HOW do I print a particular selected Report from the combo box.

I have been trying to do this for 5 days with no luck!
 
Create an On click event for the combo box.

The the event open the report
assuming your combo box is called cboReports and only has one column

DoCmd.OpenReport cboReports
 
Thanks for that tho' I was thinking of a Print Button.

However I now get a run-time error 2497
Action or method requires a ReportName argument

How do I tell it, it's the report selected????

I expect you gather I'm not an experienced Access user- but I WILL be
one day!
 
So lets say your combo box has the report name in it. On a button, use the OnClick event to create some VBA code.

Here you would use Dennisk's code ...

Code:
DoCmd.OpenReport cboReports
where cboReports is the name of your combo box.

-dK
 
I am sorry I am so THICK-

below is what I have in the VB window.
and on an 'onclick event' on a View Button.

:mad::mad::mad:
Option Compare Database

Private Sub Combo0_BeforeUpdate(Cancel As Integer)
End Sub
Private Sub View_Click()
DoCmd.OpenReport cboReports
End Sub

It is telling me to de-bug the line DoCmd............

Help!!!!!
 
Nah ... we will get you there ...

You have:

Code:
Option Compare Database

Private Sub Combo0_BeforeUpdate(Cancel As Integer)
End Sub
Private Sub View_Click()
DoCmd.OpenReport cboReports
End Sub

Make it look like ...

Code:
Option Compare Database
Option Explicit

Private Sub View_Click()
     DoCmd.OpenReport cboReports
End Sub

Make sure that your combo box name is correct - here we hav it as cboReports. If this is correct, does your combo box only look up the name of the reports? Or are there more columns (hidden and visible) contained in the combo box?

-dK
 
Thanks!

I think perhaps my combo box is set up wrong!

As it now tells me that my Reports don't exist.

I think I can see why-
I made a table for the Reports, listing them. I then made the table the source for my combo box. But there is no connection to the actual reports is there.

The action is not picking up my reports how should I have done this?

I'm getting to be a pain!!!!!
Think I need a bottle of Scotch!
 
Not necessarily, I am not sure what you mean by "But there is no connection to the actual reports is there."

-dK
 
Let's do this ....

Make your code look like:

Code:
Option Compare Database
Option Explicit

Private Sub View_Click()
     MsgBox cboReports
     'DoCmd.OpenReport cboReports
End Sub

This will cause a message box to pop up with the name of the report in the combo box. Does it have the name of the report? Or something else?

-dK
 
Sorry to be so long- had unexpected visitors.
Right I have used another db to try this out!
I have a table for Reports showing the exact name of each report.
I have a combo box which gets its source from the table, and is named cboReports
I have a command button to View, named View. The command button is set for 'onClick' [Event Procedure] with the code you gave me.
I now get 'the macro group does not exist or has not been saved......'

Should I have used a macro?

I really do appreciate the help you are giving me-
Thanks!

What I get now is a
 
A macro is not necessary - besides, I couldn't tell you how to do that because I do not use them and know nothing.

If you use what I proposed in post #9, that will tell us that your combo box is 'configured' properly. Depending on what pops up will tell us where the problem is.

-dK
 
Another probelm you may experience and I have seen this a few times is where the table containing the reports does not contain the actual report name stored in the db.

So you may have the description of the report but not the report name or you may have both but are trying to open the descriptive name and not the actual report.
 
Hi again!

Haven't sorted it yet!

I have done as 'dkinley' said, with the message box.
The message box actually shows the number of the report on the list, yes it does change with each Report name I click on in the combo box.
My report names in the box are exact names of the reports and there is only one column.

However as I click on a report name in the combo box I get an error message of 'Can't find the Macro....'


My combo box properties are:
Name...........cboReports
Row Source Type....Table/Query
RowSource.............tblReports
No event procedure-
Should I have an OnClick event telling it which report to select?
If so, how do I do that?
 
The message box actually shows the number of the report on the list, yes it does change with each Report name I click on in the combo box.
My report names in the box are exact names of the reports and there is only one column.

Strange. The message box, which is calling on the value of the combo box, shows a number; however, your report names are exact names of the reports. Are all of your reports numbers?

-dK
 
Non of the reports are numbers- the number showing in the box is the order that they appear in the list. Could it be that I have a ReportID column in the table?
I haven't shown that column in the cobmo box.
 
Nah - you're good ... it makes sense now, the problem is in how we are referring to your combo box.

In your code, we have a line that is ...
Code:
     MsgBox cboReports

Based on what you have said, your underlying rows for the cbo has at least two columns, one with the number and the other one with the name (maybe more, but it's okay as you will see). Our current reference above, references the number because the number is the bound column of the combo box. We need to get to the one with the name. Try this ...

Code:
     MsgBox cboReports.Column(1)

Run it and see what the message box pops up. If it's not the name of the report, change the (1) to (2) and keep doing this until the name pops up. In this manner we are referring to the column in the underlying row source.

Once the name pops up, change the underlying code to ..

Code:
Option Compare Database
Option Explicit
 
Private Sub View_Click()
     DoCmd.OpenReport cboReports.Column(x)
End Sub
Where (x) is the right column number discovered in the message box. This will send the right name out to fetch the report.

-dK
 
Right!
Since your last thread I have redone the combo source to a query which has just the Report list, no ID column.

I now have the message coming up as the actual report.
The code I now have is

Option Compare Database
Option Explicit
Private Sub View_Click()
MsgBox cboReports
'DoCmd.OpenReport cboReports
End Sub

If Itake out the MsgBox....... nothing happens and no error reports...
So what can I do now.
 
Correct ... You have ..

Code:
MsgBox cboReports
[COLOR=green]'DoCmd.OpenReport cboReports[/COLOR]

Notice that the second line is in green (here - I made it green for demo - but most importantly in the VBE). This is because we put an apostrophe ( ' ) there. That remarks that line so it is ignored by the compiler. That is how you document your code to leave yourself (and others notes) in the code about who, what, where, when and how.

So you can delete the msgbox because it has served it's purpose and remove the apostrophe on the DoCmd so it will do its thing.

-dK
 
Nearly there-

The reports are printing and not opening for viewing!

I would like to yhank you for your patience and help.
My next goal is to learn VB
 
I have created a combo list for Reports in my db but HOW do I print a particular selected Report from the combo box.

I have been trying to do this for 5 days with no luck!

Hehehe ... you said you wanted to print them, not view them. ;)

Okay, change the statement to ...

Code:
DoCmd.OpenReport cboReports, acPreview


-dK
 

Users who are viewing this thread

Back
Top Bottom