VB.NET - reading reports from Access MDB

B

B.Newman

I've got some VB.NET code that *should* get a list of reports from an
Access MDB and populate a list box with them.

It doesn't detect any of the reports at all. oAccess.Reports.Count
comes up as 0. There are four reports in the MDB. They are not hidden.
They don't have special characters in their names. There is no security
on the MDB and no one else is accessing it.

I have code currently to only show reports that start with "rpt_", but
I've taken that out and it doesn't help. Also, the .Count occurs before
that.

It does open the MDB just fine. If I uncomment the line to run a
specific report by name, that report runs fine as well, so I know it
can find the reports. It just can't find the .Reports collection.

Here's the code:

' Start a new instance of Access for Automation
Dim oAccess as Access.Application
Dim sDBPath as String
Dim nCount as Integer

oAccess = New Access.ApplicationClass
' Determine the path
sDBPath = gAppEnv.CvsDataPath
' open the database
oAccess.OpenCurrentDatabase(sDBPath, False)
' read in all of the available reports
nCount = oAccess.Reports.Count
For Each oRpt In oAccess.Reports
cRptName = oRpt.Name
' if it starts with "rpt_"
If cRptName.Substring(0, 4).ToLower = "rpt_" Then
lstReports.Items.Add(cRptName.Split("rpt_")(1))
End If
Next
' just run a report by name
'oAccess.Visible = True
'oAccess.DoCmd.OpenReport("rpt_Validation Error Report",
Access.AcView.acViewPreview)
 
D

Doug Bell

Hi B,

The Reports collection holds only the open reports

try
nCount = oAccess.Containers("Reports").Documents.Count
For Each oRpt In oAccess.Containers("Reports").Documents

Doug
 
B

B.Newman

Thanks, Doug, but my Access object doesn't recognize any property
called Containers. I've read that some drivers should be downloaded
from Microsoft and installed to allow better VB.Net Office automation,
but I can't install anything on my box and my users won't be able to
either. Is that the problem or can I make it work with the existing
Microsoft Access 10.0 Object Library?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top