none
Can't open an access report with vb.net RRS feed

  • Question

  • Hello,

    I'm trying to open an access report from a vb.net application. I followed the procedure described on this page: http://support.microsoft.com/default.aspx?scid=kb;[LN];317113,  but I got an error.

    here are the codes I tried:

    deconnect() 'if already connected: deconnection
    Dim oAccess As Access.Application
    oAccess = New Access.Application()
    MessageBox.Show(OConnect.State.ToString)
    oAccess.OpenCurrentDatabase(filepath:="LaPuce.mdb", Exclusive:=False) 'error 7866 db opened in exclusive mode
    oAccess.DoCmd.OpenReport(ReportName:="liste_clients", View:=Access.AcView.acViewPreview)

    or

    If connect() Then 'connection ok
                Try
                    Dim OAccess As Object
                    OAccess = CreateObject("Access.Application")
                    OAccess.DoCmd.OpenReport(nomEtat, AcView.acViewPreview) 'error on this line
                    OAccess.Visible = True
                    OAccess = Nothing
                Catch ex As Exception
                    MessageBox.Show(ex.Message) 'error saying action impossible for the moment
                Finally
                    deconnect()
                End Try

    and my connection string:

    "Provider=Microsoft.Jet.OLEDB.4.0;Data source=LaPuce.mdb;Mode=Share Deny None;"

    any idea?

    Thank you very much.



    Tuesday, June 19, 2012 8:55 AM

Answers

  • Hi Zetopskateuse,

    I never meet your problem on my side. Following is the snippet which I used to reproduce your issue.

    Imports System.Data.OleDb
    'Imports Access = Microsoft.Office.Interop.Access
    Public Class Form1
        'Private ConString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Jet OLEDB:Database Locking Mode=0"
        Private Constring1 As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Mode=Read|Share Deny Read|Share Deny Write"
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim Con As New OleDbConnection
            'Dim App As New Access.Application
            Dim App As Object = CreateObject("Access.Application")
            Dim OFD As New OpenFileDialog
            Try
                OFD.Filter = "Access DataBase 2003|*.mdb"
                OFD.Multiselect = False
                OFD.ShowDialog()
                'Con.ConnectionString = String.Format(ConString, OFD.FileName)
                Con.ConnectionString = String.Format(Constring1, OFD.FileName)
                Con.Open()
                App.Visible = True
                App.OpenCurrentDatabase(OFD.FileName, Exclusive:= False)
                App.DoCmd.OpenReport("TestTable1", 2)
                'App.DoCmd.OpenReport("TestTable1", Access.AcView.acViewPreview)
            Catch ex As Exception
                MsgBox(ex.Message)
            Finally
                Con.Close()
            End Try
        End Sub
    End Class

    Would you please try my snippet on you side?

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us



    Monday, June 25, 2012 6:52 AM
    Moderator

All replies

  • Hi zetopskateuse,

    Thanks for posting in the MSDN Forum.

    It's based on my experience that you Access file must be Opened via Exclusive model via other program or before your execute your snippet in this program.

    And I don't think it has relationship with OLEDB connect.

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

    Wednesday, June 20, 2012 4:13 AM
    Moderator
  • Thank you for your answer.

    I tried with "exclusive = true" instead of false in the first code and I tried the second code with a modified connection string:

    "Provider=Microsoft.Jet.OLEDB.4.0;Data source=LaPuce.mdb;Mode=Read|Share Deny Read|Share Deny Write;"

    but in each case I got the same error I had before.

    But maybe I didn't understand what you meant?

    Wednesday, June 20, 2012 10:24 AM
  • Hi Zetopskateuse,

    I never meet your problem on my side. Following is the snippet which I used to reproduce your issue.

    Imports System.Data.OleDb
    'Imports Access = Microsoft.Office.Interop.Access
    Public Class Form1
        'Private ConString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Jet OLEDB:Database Locking Mode=0"
        Private Constring1 As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Mode=Read|Share Deny Read|Share Deny Write"
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim Con As New OleDbConnection
            'Dim App As New Access.Application
            Dim App As Object = CreateObject("Access.Application")
            Dim OFD As New OpenFileDialog
            Try
                OFD.Filter = "Access DataBase 2003|*.mdb"
                OFD.Multiselect = False
                OFD.ShowDialog()
                'Con.ConnectionString = String.Format(ConString, OFD.FileName)
                Con.ConnectionString = String.Format(Constring1, OFD.FileName)
                Con.Open()
                App.Visible = True
                App.OpenCurrentDatabase(OFD.FileName, Exclusive:= False)
                App.DoCmd.OpenReport("TestTable1", 2)
                'App.DoCmd.OpenReport("TestTable1", Access.AcView.acViewPreview)
            Catch ex As Exception
                MsgBox(ex.Message)
            Finally
                Con.Close()
            End Try
        End Sub
    End Class

    Would you please try my snippet on you side?

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us



    Monday, June 25, 2012 6:52 AM
    Moderator
  • Hi Tom,

    Sorry for the late answer, I managed to make it work so I didn't look at this thread anymore :s

    I don't know what happened but somehow it worked just by adding OConnect.dispose after the deconnection.

    But thank you so much for your help. Your code works perfectly. I keep it on hand for the next time!

    Thursday, June 28, 2012 1:26 PM