Handling MS Access controll events in VB.Net

J

Jake

I am using an MS Access database that is opened using automation by a program
writen in VB.NET.

Many MS Access automation objects have several events, mostly corresponding
to the events exposed to VBA. For example, a CommandButton object has Click,
DblClick, Enter, Exit, etc.

If I create an object (say a commandbutton) in VB.Net and then add it at
runtime to a form in Access then I can handle all of its events normaly and
as expected.

However, if I attempt to handle an event for a commandbutton that already
exists on the access form (that is one I did not create using VB.Net) then I
get a COMException with HRESULT: 0x80040202.

I have not been able to find any information about this error or to get any
further information.

Has anyone experienced this problem or have any ideas?

Jacon
 
J

Jake

upon further researth I have discovered that this HRESULT corresponds to
either:

CONNECT_E_ADVISELIMIT
or
CONNECT_E_CANNOTCONNECT

I encountered diferent references that list these interchangibly at either
80040201 or 80040202.

I have also traced this HResult to the method:
System.Runtime.InteropServices.UCOMIConnectionPoint.Advise(Object pUnkSink,
Int32& pdwCookie)

there is information about these HResults at:
http://msdn.microsoft.com/en-us/library/cc218766.aspx

However, I am no closer to a solution. Is anyone familier with any of this?

Jacob
 
C

Cindy M.

Hi Jake,

Have you tried asking about this in a dedicated Access newsgroup? You're more
likely to find people familiar with what you're trying to do there...

FWIW I'm thinking that this might be by design. Any buttons put on a Form at
design time would be expected to be already linked to code in the Access
project. I don't think it's expected someone should be trying to "hijack" them
from outside code.
I am using an MS Access database that is opened using automation by a program
writen in VB.NET.

Many MS Access automation objects have several events, mostly corresponding
to the events exposed to VBA. For example, a CommandButton object has Click,
DblClick, Enter, Exit, etc.

If I create an object (say a commandbutton) in VB.Net and then add it at
runtime to a form in Access then I can handle all of its events normaly and
as expected.

However, if I attempt to handle an event for a commandbutton that already
exists on the access form (that is one I did not create using VB.Net) then I
get a COMException with HRESULT: 0x80040202.

I have not been able to find any information about this error or to get any
further information.

Has anyone experienced this problem or have any ideas?

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 
J

Jake

I will try in the access group. In the past I have found that the people
there don't tend to answer questions about automation.

If you didn't want people to use these events then why put them in the PIAs
to begin with. Some of these objects Can't be created using automation.
Actualy, they can be instantiated but not displayed.

For example it is imposible to instantiate an Access form in VB .Net and
then display it to the user. You can if it is instantiated in vba but then
this error happens when I add an event handler. - Catch 22.

Jacob
 
C

Cindy M.

Hi Jake,
If you didn't want people to use these events then why put them in the PIAs
to begin with.
Whoa, slow down there :) "You": I have no control over what Microsoft does
with their software.

My remark about why you might be having difficulties was a guess as to the
reason.

The events have to be in the object model if VBA is going to use them. The
PIA interface between the COM type library and .NET picks up "everything",
even things that aren't exposed in VBA, but are necessary for the interface
to function.
For example it is imposible to instantiate an Access form in VB .Net and
then display it to the user. You can if it is instantiated in vba but then
this error happens when I add an event handler. - Catch 22.
I'm peripherally acquainted with Access, but I've rarely tried to automate
the interface from outside Access. Since I can link up to the data base with
no problems, I've never really seen the need to use an Access form from
within classic VB or .NET application.

I'm not quite sure how to interpret "instantiate... then display". My first
reaction is that Office really doesn't support doing things in this manner. A
thing has to be physically available in the application interface before I
can work with it. So I have to use some kind of OPEN method on the Applicatin
object in order to "instantiate" the object. (I can declare it, but can't
instantiate/populate before it actually exists in the application.)

But I'm not sure if this is how you mean it...

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top