Opening an Access report using VB.NET

I’m using this code that I found on vb.net Macorotti, which I’ve adapted to run Visual Studio 2019. It works when printing, but when I ask it to preview the AcWindowMode.acWindowNormal report, it sends it to the printer too. Help me find a solution.

Imports Microsoft.Office.Interop.Access

Public Class Frm_AccessRelatorio
    Private Sub Frm_AccessRelatorio_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        cboRelatorios.SelectedIndex = 0
        BtnFechar.Focus()

    End Sub

    Private Sub BtnExecutar_Click(sender As Object, e As EventArgs) Handles BtnExecutar.Click

        If cboRelatorios.SelectedIndex = -1 Then
            MessageBox.Show("Selecione um relatório", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Information)
            Return
        End If
        Try
            Dim MSA As New Microsoft.Office.Interop.Access.Application
            MSA.Application.Visible = False

            MSA.OpenCurrentDatabase(strPath & "Teste.accdb", False)

            If rdbVisualizar.Checked Then
                MSA.Application.DoCmd.OpenReport(cboRelatorios.Text, Microsoft.Office.Interop.Access.AcWindowMode.acWindowNormal)
                'maximiza a janela
                MSA.Application.DoCmd.Maximize()

            Else
                MSA.Application.DoCmd.OpenReport(cboRelatorios.Text, Microsoft.Office.Interop.Access.AcView.acViewNormal)
            End If

        Catch ex As Exception
            MessageBox.Show("Erro : " & ex.Message, "Erro ao acessar o objeto", MessageBoxButtons.OK, MessageBoxIcon.Information)
        End Try
    End Sub
End Class

I have no idea how to solve it.

New contributor

Manuel Lapa is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

It sends to the printer, since that’s what “normal” means in VBA, and hence it means the same thing in vb.net.

Next up, if you trying to preview the report, then you have to make Access visible, and you have visible = False, which of course will defeat your whole goal here to display the report in place of printing the report.

So, this code works for me:

    Dim MSA As New Microsoft.Office.Interop.Access.Application

    MSA.Application.Visible = True

    MSA.OpenCurrentDatabase("c:testtest444.accdb", False)


    MSA.Application.DoCmd.OpenReport("rptHotelsA",
       Microsoft.Office.Interop.Access.AcView.acViewPreview)

Note the use of “preview” in place of “Normal”, since as noted, normal = send directly to printer.

On the other hand, it not at all clear why you want to launch a copy of Access in VB, and then launch a report, since such a process is far better served by doing this in Access without introduction of VB code.

However, regardless of your goals here, you need to open the report in “preview” mode, not “normal”, and to see the report, you have to set the Access application object with Visible = true.

Edit: Hiding most of the Access interface.

In the comments, the question was how to hide the Access interface.

As I pointed out, you can hide most, if not all of the Access UI, and only show the report.

The settings in Access are:

Use tabbed interface, turn off tabs.

Hence, file->options->Current Database->Document windows options.

So, set tabbed interface (not overlapping windows), and turn off display of tabs.

Hence this:

Then under navigation, turn off display of navigation pane.

Hence this:

As noted, at this point, then the only UI will be the report, and the report ribbon. I often like and want the report ribbon, since it allows the user to send/save the report to a PDF, or print the report.

So, now the result of above is a window with a report, and only the report and the report ribbon displays. And if you use acReportView, then the report ribbon does not even display.

And if you re-size the Access window, the report will always re-size to the given window size you have. The result is this:

As noted, you could I suppose turn off the ribbon.

Hence, with this vb.net code:

    Dim MSA As New Microsoft.Office.Interop.Access.Application

    MSA.Application.Visible = True

    MSA.OpenCurrentDatabase("c:testtest444.accdb", False)

    MSA.Application.DoCmd.ShowToolbar("Ribbon", 2)

    MSA.Application.DoCmd.OpenReport("rptHotelsA",
       Microsoft.Office.Interop.Access.AcView.acViewReport)

And now the result is just a window with the report.

Hence:

So, with just a few simple settings, you can with ease hide most of the Access UI.

5

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật