| re: VB.NET - reading reports from Access MDB
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" <b2newman@or.blm.gov> wrote in message
news:1103558081.487147.24880@f14g2000cwb.googlegro ups.com...[color=blue]
> 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)
>[/color] |