Opening a report selected from a combo list

AccessAM

Registered User.
Local time
Today, 23:30
Joined
Mar 6, 2012
Messages
17
Hi Chaps
I have a combo list that populates with all the reports in the database on load.

I want to create button so that the user selects the report from the list and then clicks the button to run the selected report. I'm having some difficulties writing the code. Here's my efforts so far
Let's say combo list control is named ReportsList

Private Sub Command14_Click()
DoCmd.OpenReport "ReportsList.Value"
End Sub

Any help will be gratefully received.
 
Remove the quotes.. if you use quotes after the OpenReport statement it thinks you are passing a Report named "ReportsList.Value".. just place DoCmd.OpenReport ReportsList.Value
 
Thanks for your suggestion, but I get the following error message:
Runtime error 424
Object required
Any ideas?
 
I'm still struggling with this one.
The code behind the combo list looks like this:

Private Sub Form_Load()
Dim NewValList As String
NewValList = ""
Dim obj As AccessObject
For Each obj In CurrentProject.AllReports
NewValList = NewValList & Chr(34) & obj.Name & Chr(34) & ";"
Next obj
Me!ReportsList.RowSourceType = "Value List"
Me!ReportsList.RowSource = NewValList
Me!ReportsList.Value = Me!ReportsList.ItemData(0)
End Sub

It works OK - all the reports in the project appear in the list but I now want the reports to load. Ideally, I would like a cmd button to click as I mentioned in my original post, or if that isn't possible, it would be sufficient for the report to load on selection.

Any ideas how I can do this?
 
Hi, Sorry was away for the Bank holiday weekend, and could not get back to this. What I have shown should work. I am not sure why you have to do the second bit of coding. I mean all you needed to do was.. something like this..
Code:
Private Sub Form_Load()
    Dim obj As AccessObject
    Me!ReportsList.RowSourceType = "Value List"
    For Each obj In CurrentProject.AllReports
        Me!ReportsList.AddItem obj.Name
    Next obj
    Me!ReportsList.Value = Me!ReportsList.ItemData(0)
End Sub
 
Hi again,
I tried removing the "" as you suggested (and tried various combinations) but with no success........
 
Is it possible for you to upload a sample DB stripping all sensitive information.. I really do not see any complications..
 
Here you go - please see the form frmTEST where the combobox and cmd button are. Please be aware that for some reason the cmd button sometimes wants to send the selected report to print!
Thanks
 

Attachments

Am so sorry for not responding, for some reason, I did not get any notifications.. I was checking my CP and found I have replies. Well I changed the view to be
Code:
DoCmd.OpenReport ReportsList.Value, acViewReport
it worked fine.

Again sorry..
 
No probs - I really appreciate your help.
For some reason it seems to want to send the selected report to print - must be a local computer setting or something - have you experienced anything like that before?
 
If you look at pr2-eugin's code he has set the the second parameter to acViewReport. You need to set that parameter to what he's given or use acPreview.
 
Yes, it now works perfectly - it was set as acViewNormal - my fault didn't follow the instructions.
Thanks all
 
You are welcome AccessAM..

Well any thanks that are given to me indirectly inclines to you vbaInet.. I hope you know that.. :)
 

Users who are viewing this thread

Back
Top Bottom