By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,663 Members | 2,152 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,663 IT Pros & Developers. It's quick & easy.

VB.NET - reading reports from Access MDB

P: n/a
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)

Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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.Newman" <b2******@or.blm.gov> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...
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)

Nov 21 '05 #2

P: n/a
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?

Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.