Determining if an Access Project is open

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Kenneth Courville

    Determining if an Access Project is open

    Hello, I'm looking for assistance with the Access object model. I know
    this is VB, but I'm building an Office Add-using C# directed at Access
    2002. I'm literate in VB, so you can reply in VB... I think my problem
    mainly lies in knowing the quirks of the Access object model.

    Basically, I'm looking for a method of determining if an Access database
    is open yet. AND I'm looking for a method that doesn't not require
    checking for an exception. It seems that even handled exceptions will
    cause the add-in to not close properly.... eating up memory.

    Currently, I have a timer that starts upon opening Access. Every 1/2
    second, the timer_elasped event checks to see if a database is open.

    So far, I found that I can check the property Application.For ms.Count >
    0, which doesn't throw an exception if a database isn't open yet, but
    still seems to cause the MSACCESS process to not close entirely upon
    exit. And I've isolated the code the the use of this property. If I
    take it out, the MSACCESS closes fine.

    Ultimately, the process I'm try to automate:
    - User opens Access.
    - Add-in launches and waits for a database to be loaded.
    - Database is loaded.
    - Add-in detects database is opened
    - Add-in determines if the current database is an ADE or ADP file
    (Access Project).

    If anyone has other suggestions for accomplishing this, I would greatly
    appreciate it.

    Thanks.

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
  • Salad

    #2
    Re: Determining if an Access Project is open

    Kenneth Courville wrote:
    [color=blue]
    > Hello, I'm looking for assistance with the Access object model. I know
    > this is VB, but I'm building an Office Add-using C# directed at Access
    > 2002. I'm literate in VB, so you can reply in VB... I think my problem
    > mainly lies in knowing the quirks of the Access object model.
    >
    > Basically, I'm looking for a method of determining if an Access database
    > is open yet. AND I'm looking for a method that doesn't not require
    > checking for an exception. It seems that even handled exceptions will
    > cause the add-in to not close properly.... eating up memory.
    >
    > Currently, I have a timer that starts upon opening Access. Every 1/2
    > second, the timer_elasped event checks to see if a database is open.
    >
    > So far, I found that I can check the property Application.For ms.Count >
    > 0, which doesn't throw an exception if a database isn't open yet, but
    > still seems to cause the MSACCESS process to not close entirely upon
    > exit. And I've isolated the code the the use of this property. If I
    > take it out, the MSACCESS closes fine.
    >
    > Ultimately, the process I'm try to automate:
    > - User opens Access.
    > - Add-in launches and waits for a database to be loaded.
    > - Database is loaded.
    > - Add-in detects database is opened
    > - Add-in determines if the current database is an ADE or ADP file
    > (Access Project).
    >
    > If anyone has other suggestions for accomplishing this, I would greatly
    > appreciate it.
    >
    > Thanks.
    >
    > *** Sent via Developersdex http://www.developersdex.com ***
    > Don't just participate in USENET...get rewarded for it![/color]

    Don't know. However, it seems you want to close Access cleanly. I
    suppose you have a form that is open with your timer interval. In the
    OnClose or OnDeavtivate event of the form set your timer interval to 0.
    Make sure the form closes correctly.

    Comment

    • MGFoster

      #3
      Re: Determining if an Access Project is open

      Kenneth Courville wrote:
      [color=blue]
      > Hello, I'm looking for assistance with the Access object model. I know
      > this is VB, but I'm building an Office Add-using C# directed at Access
      > 2002. I'm literate in VB, so you can reply in VB... I think my problem
      > mainly lies in knowing the quirks of the Access object model.
      >
      > Basically, I'm looking for a method of determining if an Access database
      > is open yet. AND I'm looking for a method that doesn't not require
      > checking for an exception. It seems that even handled exceptions will
      > cause the add-in to not close properly.... eating up memory.
      >
      > Currently, I have a timer that starts upon opening Access. Every 1/2
      > second, the timer_elasped event checks to see if a database is open.
      >
      > So far, I found that I can check the property Application.For ms.Count >
      > 0, which doesn't throw an exception if a database isn't open yet, but
      > still seems to cause the MSACCESS process to not close entirely upon
      > exit. And I've isolated the code the the use of this property. If I
      > take it out, the MSACCESS closes fine.
      >
      > Ultimately, the process I'm try to automate:
      > - User opens Access.
      > - Add-in launches and waits for a database to be loaded.
      > - Database is loaded.
      > - Add-in detects database is opened
      > - Add-in determines if the current database is an ADE or ADP file
      > (Access Project).
      >
      > If anyone has other suggestions for accomplishing this, I would greatly
      > appreciate it.[/color]

      -----BEGIN PGP SIGNED MESSAGE-----
      Hash: SHA1

      I believe there is some confusion about terminology, which may be caused
      by the various definitions of "Database." Database can refer to an ODBC
      database (Paradox, dBase, MS SQL Server, Oracle, etc.), or to an Access
      database (file extensions: .mdb, .mde). ADP/E files are front-ends
      connected to databases (tables, queries, stored procedures, views,
      functions).

      There is some confusion in Microsoft's own terminology. There is a
      method, OpenDatabase (DAO), that can open an .mdb/e file. These files
      are considered database files, but, they do not necessarily have any
      tables in them.

      "Application.Fo rms.Count" only counts the number of open forms in an
      application. It does not determine if a database is open. A form can
      be open w/o a database (tables/queries) being open. Forms can be bound
      to tables/queries or unbound (not linked to tables/queries).

      So the question is, "What do you mean by 'database'?" This begs the
      question "Why do you want to know if a 'database' is open? What will
      that tell you?"

      Perhaps you'd be better served by using the CurrentProject. Name
      property. In Access 2000, and higher versions, this property will
      return the name of the file, which will have the extension you are
      looking for.

      <NitPick>
      An .ADE file is a "locked" .ADP file. They are both Access Project
      files. Locked means the forms, reports & VBA code modules are not
      viewable nor editable.
      </NitPick>

      --
      MGFoster:::mgf0 0 <at> earthlink <decimal-point> net
      Oakland, CA (USA)

      -----BEGIN PGP SIGNATURE-----
      Version: PGP for Personal Privacy 5.0
      Charset: noconv

      iQA/AwUBQH2kAIechKq OuFEgEQK6XACgha nLn33eZisG1gssC qyyxxq/Gf4AoJkX
      t/1ndKS3+SJJorG5n But8lpe
      =dnS9
      -----END PGP SIGNATURE-----

      Comment

      • Kenneth Courville

        #4
        Re: Determining if an Access Project is open

        Actually, at this point, I'm not really concerned about forms... just
        the Access application.

        The add-in has a shutting down event that is fired when you close
        Access. I'm using this to stop and destroy the timer properly.

        Right now, the code that is causing the issue is the code that checks to
        see if an Access database or project is loaded. If I take it out, the
        MSACCESS process closes properly.

        I wanted to avoid posting C# code under VB, but maybe it'll help...
        Here is my timer_Elasped event... the problematic lines are marked with
        arrows:

        private void timer_Elapsed(o bject sender, ElapsedEventArg s e)
        {
        string projectName = "";

        // Get project name
        // If no name exists yet, set project name to a blank value
        try
        {
        --> if( applicationObje ct.Forms.Count > 0 )
        --> {
        --> projectName = applicationObje ct.CurrentProje ct.Name;
        --> }
        --> else
        --> projectName = "";
        }
        catch( Exception ex )
        {
        System.Diagnost ics.Debug.Write Line( ex.StackTrace );
        projectName = "";
        }
        catch
        {
        System.Diagnost ics.Debug.Write Line( "unknown exception" );
        }
        // If an Access Project is loaded, load the Access Manager Bar
        if( projectName.ToU pper().EndsWith (COMPILED_PROJE CT_EXTENSION) ||
        projectName.ToU pper().EndsWith (PROJECT_EXTENS ION) )
        {
        timer.Stop();
        CreateCommandBa r();
        }

        }

        *** Sent via Developersdex http://www.developersdex.com ***
        Don't just participate in USENET...get rewarded for it!

        Comment

        • Kenneth Courville

          #5
          Re: Determining if an Access Project is open

          Please review:
          Ultimately, the process I'm try to automate:
          - User opens Access.
          - Add-in launches and waits for a database to be loaded.
          - Database is loaded.
          - Add-in detects database is opened
          - Add-in determines if the current database is an ADE or ADP file
          (Access Project).

          By "database", I mean an Access "document": mdb, mde, ade, adp, etc.

          Basically, if the user opens Access first, instead of directly opening
          an Access "document" from a shortcut or via browsing with Windows
          Explorer, I want to wait and detect when a document is opened.

          CurrentProject. Name throws an exception if a document isn't loaded yet,
          and you try to access it. I'm trying to find a method that does not
          require you to trap an exception.



          *** Sent via Developersdex http://www.developersdex.com ***
          Don't just participate in USENET...get rewarded for it!

          Comment

          • MGFoster

            #6
            Re: Determining if an Access Project is open

            Kenneth Courville wrote:
            [color=blue]
            > Please review:
            > Ultimately, the process I'm try to automate:
            > - User opens Access.
            > - Add-in launches and waits for a database to be loaded.
            > - Database is loaded.
            > - Add-in detects database is opened
            > - Add-in determines if the current database is an ADE or ADP file
            > (Access Project).
            >
            > By "database", I mean an Access "document": mdb, mde, ade, adp, etc.
            >
            > Basically, if the user opens Access first, instead of directly opening
            > an Access "document" from a shortcut or via browsing with Windows
            > Explorer, I want to wait and detect when a document is opened.
            >
            > CurrentProject. Name throws an exception if a document isn't loaded yet,
            > and you try to access it. I'm trying to find a method that does not
            > require you to trap an exception.[/color]

            -----BEGIN PGP SIGNED MESSAGE-----
            Hash: SHA1

            Again, it may be a terminology problem (in addition to the operational
            problem you've reported). In Access development an "add-in" is,
            usually, an Access "database" file, what you call a document. It is
            usually meant to be used as a development aid, though it can be used in
            applications. It becomes part of the Access interface/IDE when it is
            registered by the Access "Add-in Manager," which is also an add-in (one
            of the standard Access wizards). The add-in then becomes part of the
            Access environment on the PC on which it was registered.

            I'm not sure what I'd call you're program. It sounds like something
            that is running BEFORE Access starts, which would mean it'd have to be
            "watching" the Windows Messages (using the Windows APIs) to "know" when
            Access was loaded; then watch that instance of Access and wait until a
            "document" was loaded. This is not an Access "add-in."

            Perhaps, the answer lies outside the realm of Access development. There
            is an MS newsgroup devoted to C#:

            microsoft.publi c.dotnet.langua ges.csharp

            where you may have more success in finding help.

            Rgds,

            --
            MGFoster:::mgf0 0 <at> earthlink <decimal-point> net
            Oakland, CA (USA)

            -----BEGIN PGP SIGNATURE-----
            Version: PGP for Personal Privacy 5.0
            Charset: noconv

            iQA/AwUBQH7ho4echKq OuFEgEQKpjACfVY BSdnVjO2tPljczX VANmxvXCXwAoOTD
            S/4Xgk2ohHWEkCw1o rnTDe9k
            =fqsR
            -----END PGP SIGNATURE-----

            Comment

            • Kenneth Courville

              #7
              Re: Determining if an Access Project is open

              Maybe I should say "COM Add-in" instead.

              These can be built in VB as well, refer to




              *** Sent via Developersdex http://www.developersdex.com ***
              Don't just participate in USENET...get rewarded for it!

              Comment

              Working...