By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,665 Members | 1,454 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,665 IT Pros & Developers. It's quick & easy.

Determining if an Access Project is open

P: n/a
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.Forms.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!
Nov 12 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Kenneth Courville wrote:
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.Forms.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!


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.

Nov 12 '05 #2

P: n/a
Kenneth Courville wrote:
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.Forms.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.


-----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.Forms.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:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

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

iQA/AwUBQH2kAIechKqOuFEgEQK6XACghanLn33eZisG1gssCqyyxx q/Gf4AoJkX
t/1ndKS3+SJJorG5nBut8lpe
=dnS9
-----END PGP SIGNATURE-----

Nov 12 '05 #3

P: n/a
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(object sender, ElapsedEventArgs e)
{
string projectName = "";

// Get project name
// If no name exists yet, set project name to a blank value
try
{
--> if( applicationObject.Forms.Count > 0 )
--> {
--> projectName = applicationObject.CurrentProject.Name;
--> }
--> else
--> projectName = "";
}
catch( Exception ex )
{
System.Diagnostics.Debug.WriteLine( ex.StackTrace );
projectName = "";
}
catch
{
System.Diagnostics.Debug.WriteLine( "unknown exception" );
}
// If an Access Project is loaded, load the Access Manager Bar
if( projectName.ToUpper().EndsWith(COMPILED_PROJECT_EX TENSION) ||
projectName.ToUpper().EndsWith(PROJECT_EXTENSION) )
{
timer.Stop();
CreateCommandBar();
}

}

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

P: n/a
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!
Nov 12 '05 #5

P: n/a
Kenneth Courville wrote:
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.


-----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.public.dotnet.languages.csharp

where you may have more success in finding help.

Rgds,

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

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

iQA/AwUBQH7ho4echKqOuFEgEQKpjACfVYBSdnVjO2tPljczXVANmx vXCXwAoOTD
S/4Xgk2ohHWEkCw1ornTDe9k
=fqsR
-----END PGP SIGNATURE-----

Nov 12 '05 #6

P: n/a
Maybe I should say "COM Add-in" instead.

These can be built in VB as well, refer to
http://support.microsoft.com/default...b;EN-US;238228

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

This discussion thread is closed

Replies have been disabled for this discussion.