Using ".OpenCurrentDatabase" in VB .net to open an MS Access DB

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Paul M

    Using ".OpenCurrentDatabase" in VB .net to open an MS Access DB

    Hello,
    when I execute the code below I get the usual access message:

    SECURITY WARNING----------------------------------

    Opening "<filepath & name.mdb>"

    The file may not be safe if it contains code that was intended
    to harm your computer.
    Do you want to cancel the operation?

    CANCEL OPEN MORE INFO

    ---------------------------------------------------

    Private Sub OpenDB(ByVal strMDBFullPath as string)

    Dim appDatabase As Access.Applicat ion

    appDatabase = New Access.Applicat ion()
    appDatabase.Ope nCurrentDatabas e(p_strMDBFullP ath, True)

    ....

    End Sub

    How can I detect if the user presses the CANCEl button? With the code
    above if the user presses the CANCEl button the code throws an exception
    on the line "appDatabase.Op enCurrentDataba se(p_strMDBFull Path, True)".

    The code is VB .net and the database is 2003 but could be 97, 2000 etc.

    Thanks in advance

    Paul M.



  • Armin Zingler

    #2
    Re: Using &quot;.OpenCurr entDatabase&quo t; in VB .net to open an MS Access DB

    "Paul M" <paul@nospam.co .uk> schrieb[color=blue]
    > Hello,
    > when I execute the code below I get the usual access message:
    >
    > SECURITY WARNING----------------------------------
    >
    > Opening "<filepath & name.mdb>"
    >
    > The file may not be safe if it contains code that was intended
    > to harm your computer.
    > Do you want to cancel the operation?
    >
    > CANCEL OPEN MORE INFO
    >
    > ---------------------------------------------------
    >
    > Private Sub OpenDB(ByVal strMDBFullPath as string)
    >
    > Dim appDatabase As Access.Applicat ion
    >
    > appDatabase = New Access.Applicat ion()
    > appDatabase.Ope nCurrentDatabas e(p_strMDBFullP ath, True)
    >
    > ...
    >
    > End Sub
    >
    > How can I detect if the user presses the CANCEl button? With the code
    > above if the user presses the CANCEl button the code throws an exception
    > on the line "appDatabase.Op enCurrentDataba se(p_strMDBFull Path, True)".[/color]


    Catch the exception. See the 'Try' and 'catch' keywords.


    Armin

    Comment

    • m.posseth

      #3
      Re: Using &quot;.OpenCurr entDatabase&quo t; in VB .net to open an MS Access DB



      I wonder what you are trying to do

      do you want to retrieve data from the access database ?

      if so this is not the way ( you propbaly have set a reference to the office
      lib )

      normally you access a access database by the oledb namespace

      regards

      Michel Posseth [MCP]



      "Paul M" <paul@nospam.co .uk> wrote in message
      news:dpo6cl$aes $1@newsg3.svr.p ol.co.uk...[color=blue]
      > Hello,
      > when I execute the code below I get the usual access message:
      >
      > SECURITY WARNING----------------------------------
      >
      > Opening "<filepath & name.mdb>"
      >
      > The file may not be safe if it contains code that was intended
      > to harm your computer.
      > Do you want to cancel the operation?
      >
      > CANCEL OPEN MORE INFO
      >
      > ---------------------------------------------------
      >
      > Private Sub OpenDB(ByVal strMDBFullPath as string)
      >
      > Dim appDatabase As Access.Applicat ion
      >
      > appDatabase = New Access.Applicat ion()
      > appDatabase.Ope nCurrentDatabas e(p_strMDBFullP ath, True)
      >
      > ...
      >
      > End Sub
      >
      > How can I detect if the user presses the CANCEl button? With the code
      > above if the user presses the CANCEl button the code throws an exception
      > on the line "appDatabase.Op enCurrentDataba se(p_strMDBFull Path, True)".
      >
      > The code is VB .net and the database is 2003 but could be 97, 2000 etc.
      >
      > Thanks in advance
      >
      > Paul M.
      >
      >
      >[/color]


      Comment

      • Cyril Gupta

        #4
        Re: Using &quot;.OpenCurr entDatabase&quo t; in VB .net to open an MS Access DB

        Hello Paul,

        You have cross-posted to a lot of groups.

        Your answer is in your question. When the user presses Cancel you get an
        error, so trap the error and use it.

        Here's what you can do.

        Try
        Your Code
        Catch ex as exception
        do something with the exception
        End Try

        That should solve it for you Paul

        Cyril Gupta


        Comment

        • TC

          #5
          Re: Using &quot;.OpenCurr entDatabase&quo t; in VB .net to open an MS Access DB

          No to answer your question, but: do you really want to open that
          database /in the Access user interface/? Or do you just want to open
          it "behind the scenes", so you can get at the data within it?

          If the latter, then, you need OpenDatabase - not OpenCurrentData base.

          HTH,
          TC [MVP Access]

          Comment

          • Paul M

            #6
            Re: Using &quot;.OpenCurr entDatabase&quo t; in VB .net to open an MS AccessDB

            Cyril Gupta wrote:[color=blue]
            > Hello Paul,
            >
            > You have cross-posted to a lot of groups.
            >
            > Your answer is in your question. When the user presses Cancel you get an
            > error, so trap the error and use it.
            >
            > Here's what you can do.
            >
            > Try
            > Your Code
            > Catch ex as exception
            > do something with the exception
            > End Try
            >
            > That should solve it for you Paul
            >
            > Cyril Gupta
            >
            >[/color]
            Hello Cyril,
            thanks for that, I had already considered that but just wanted a more
            elegegant way of doing ie testing a return value, that sort of thing.

            Thanks
            Paul

            Comment

            Working...