Re: MS Access Reports and VB.NET Program



You need to have the Access application installed (not just the mdb file) on
the computer you want to run the report. Try using this code: (watch out
for word wrap)

Public Sub PrintAccessReport(ByVal sReportName As String, Optional ByVal
sQryName As String = "", Optional ByVal sSQL As String = "")
Dim oAccess As New Access.ApplicationClass
oAccess.Visible = True
oAccess.OpenCurrentDatabase("C:\PathTo\Your\Database.mdb")
oAccess.DoCmd.Minimize()
'Create new query if needed
If sQryName.Length > 0 And sSQL.Length > 0 Then
Try
'oAccess.CurrentDb.QueryDefs.Delete(sQryName)
oAccess.DoCmd.DeleteObject(Access.AcObjectType.acQuery, sQryName)
Catch
'Close and reopen the Access object if above statement failed
oAccess.Visible = False
oAccess.Quit(Access.AcQuitOption.acQuitSaveNone)
System.Runtime.InteropServices.Marshal.ReleaseComObject(oAccess)
oAccess.Visible = True
oAccess.OpenCurrentDatabase("C:\PathTo\Your\Database.mdb")
oAccess.DoCmd.Minimize()
End Try
oAccess.CurrentDb.CreateQueryDef(sQryName, sSQL)
End If
'Preview the report
oAccess.DoCmd.OpenReport(sReportName, Access.AcView.acViewPreview, , ,
Access.AcWindowMode.acDialog)
'Close the Access Instance
If Not oAccess Is Nothing Then
' Call Access Quit method without saving any changes.
oAccess.Quit(Access.AcQuitOption.acQuitSaveNone)
' Use Marshal class' ReleaseComObject to release the Access instance.
System.Runtime.InteropServices.Marshal.ReleaseComObject(oAccess)
' Dereference the oAccess variable.
oAccess = Nothing
End If
End Sub

--
------------------------------------------------------------------------
George Shubin Custom Software Development
dX Software Systems Database Applications
Ph: 503-981-6806 Fax: 503-982-0120
www.dxonline.com george@xxxxxxxxxxxx
------------------------------------------------------------------------

"JoeW" <wajo0401@xxxxxxxxxxxxxxxx> wrote in message
news:1155745516.792909.268870@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I'm utilizing a database that I created within MS Access within a
program I've created in VB.NET. I am using the VB front end to
navigate the information, but want to be able to print a report, that
I've also created within MS Access. I've attempted using the
Access.Application instance, but I get errors when it tries to load the

database. Just wondering if anyone has any experience with this, and
what I should do.

Thanks for any help you can offer.



.



Relevant Pages

  • Re: MS Access Reports and VB.NET Program
    ... the computer you want to run the report. ... Dim oAccess As New Access.ApplicationClass ... ' Use Marshal class' ReleaseComObject to release the Access instance. ... George Shubin Custom Software Development ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Dim oRpt As New CrystalReport1() failing
    ... the public sub reportprod doesn't seem to be doing much when I test. ... So, now, I want my "vendor" parameter to call the report with discrete values and not show the crystal report default parameter dialog box. ... Imports System.Data.OleDb ... Dim pdvProdId As New CrystalDecisions.Shared.ParameterDiscreteValue ...
    (microsoft.public.dotnet.languages.vb)
  • Drop Down List Problem
    ... Public Sub _OnSelectedIndexChanged1(ByVal Sender As Object, ... If DropDownList1.SelectedValue = "Choose a Report Category" ... If DropDownList1.SelectedValue = "DailyReports" ... Drop down list navigation is all working, just when the back button is ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Macro/VBA to delete rows in Spreadsheet
    ... Public Sub SelectiveDelete() ... Dim LRowData As Long, ir As Long ... I have a text report that is pulled into Excel which I then sort & then ... It then needs to check column B for an "@" symbol or blank cells & again ...
    (microsoft.public.excel.programming)
  • RE: Opening a report in a different access database
    ... "Clifford Bass" wrote: ... linked tables in your reports database so that you do not actually need to ... Public Sub PreviewARemoteReport ... ' Make sure the report is closed so it will use up-to-date ...
    (microsoft.public.access.tablesdbdesign)

Loading