473,320 Members | 2,161 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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.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
6 3605
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: bill | last post by:
I am trying to convince a client that dotNet is preferable to an Access project (ADP/ADE). This client currently has a large, pure Access MDB solution with 30+ users, which needs to be upgraded....
1
by: MVM | last post by:
I am creating a form in an Access project, using SQL Server as the backend. The project is linked to two tables, Departments and FixedAssets. The form I am working with is linked to FixedAssets. ...
1
by: damjanu | last post by:
Hi; I have spent some time investigating this issue, and I would like to verify with you my findings. I would greatly appreciate someone experianced saying yes to what I concluded, or no and...
7
by: damjanu | last post by:
Hi All; I need little help. I have a datasheet form. I allow user to do 'filter by selection'. My form contains a column with values. As user changes selections, I want to calculate totals....
0
by: Bob Davies | last post by:
I have an SQL Server database which I have upsized from Access. I have written a Procedure in SQL Server which creates a new table based on joining several other tables. However, Access Project...
6
by: Kenneth Courville | last post by:
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...
11
by: Tim Smallwood | last post by:
Hi, I have an Access project that I use to allow a client to hit an SQL server at my host. This project has several forms that are used to udpate tables, etc, but I'd also like to be able to...
1
by: Jim Devenish | last post by:
I am continuing my exploration about upsizing to SQLServer from Access 2000. I have a split database with a front-end and a back-end, each of which is A2K. I have spent some time in bookshops...
1
by: GAVO-UK | last post by:
Hi - Using Access 2003 I've been creating applications in access for the past few years and gotten pretty good at it, now I would like to move a bit forward and start using ms access project. ...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.