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

Addin calling function in Parent

P: n/a
Dear All,

I have an MDB file (Access 2000/XP) which contains generic routines I
use in various apps (eg, API calls, File access classes etc).

I have compiled into an MDE file which I reference in VBA from my other
Access applications.

This works fine and I'm quite happy with it... except for one area;
error handling. In most of my functions I call an error handler which
stores the details of the error into a table so that I can review the
error log in future. What I would like is for my ADDIN to call the
error function stored in the CALLING application so that any errors
that occur in the addin are recorded and actioned as per the error
handler of the calling function... is this possible? If I try to refer
to a generic error handler (eg HandleError(errmsg, err) from the ADDIN,
ofcourse the compiler complains this function doesn't exist because it
doesn't know that I'm using this MDE as an addin in future... if I add
a REFERENCE to my calling app, then that means that ADDIN will only
work for that app !?

In case thats not very clear heres an example of what I'm attempting;

Calling app: Main.MDB
function test()
call testaddin()
end function

function HandleError(ErrMsg as string, Err as integer)
' Code to save error in local table etc..
' ....
end function

Addin App: ADDIN.MDE
function testaddin()
on error goto handleerror

dim a as integer

a = 0/0

errexit:
exit function

handleerror:
HandleError("Error Occurred", err)
resume errexit
end function

- results in a compile error as Handle Error is not known in the
ADDIN.mde....
If this isn't possible, am I perhaps trying to achieve this in the
wrong way and there is a better option/idea??

Many thanks,

Ju Chao

Nov 13 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
jc******@hotmail.com wrote:
Dear All,

I have an MDB file (Access 2000/XP) which contains generic routines I
use in various apps (eg, API calls, File access classes etc).

I have compiled into an MDE file which I reference in VBA from my other
Access applications.

function HandleError(ErrMsg as string, Err as integer)
' Code to save error in local table etc..
' ....
end function


What happens if you put HandleError in each MDB/MDE?
Nov 13 '05 #2

P: n/a
Salad <oi*@vinegar.com> wrote in message news:<Mc*****************@newsread1.news.pas.earth link.net>...
jc******@hotmail.com wrote:
[SNIP]


What happens if you put HandleError in each MDB/MDE?


Well, it will compile but then my generic MDE would be hard coded to
work with only 1 particular HandleError routine...

This is an issue because, for example, if:
1. DB 1 saves errors in d:\db\dberr.mdb
2. DB 2 only displays errors
3. DB 3 saves errors in d:\db3\dberr.mdb

My Generic MDE file should call the Calling Apps HandleError routine
and so perform the appropriate function when an error occurs.

Regards

Ju Chao
Nov 13 '05 #3

P: n/a
Ju Chao wrote:
Salad <oi*@vinegar.com> wrote in message news:<Mc*****************@newsread1.news.pas.earth link.net>...
jc******@hotmail.com wrote:

[SNIP]


What happens if you put HandleError in each MDB/MDE?

Well, it will compile but then my generic MDE would be hard coded to
work with only 1 particular HandleError routine...

This is an issue because, for example, if:
1. DB 1 saves errors in d:\db\dberr.mdb
2. DB 2 only displays errors
3. DB 3 saves errors in d:\db3\dberr.mdb

My Generic MDE file should call the Calling Apps HandleError routine
and so perform the appropriate function when an error occurs.

Regards

Ju Chao


I added a reference to Northwind. I then opened Northwind and attempted
to create a reference to the main app. It would not do that, and it
complained of a circular reference.

So I tried something else. This concept may do what you want. You'll
need to modify it to your needs.

In DB1, I created the following routines in Module1. I also created a
reference to Northwind.

Sub Junk()
JunkExternal
MsgBox "I'm back again"
End Sub

Public Sub JunkMain()
MsgBox "Hello from Main Module"
End Sub
I opened Northwind and then added the following routines.
Public Sub JunkExternal()
MsgBox "Hello From Module Northwind"
RunAccessSub
End Sub

Public Sub RunAccessSub()
Set appAccess = CreateObject("Access.Application.8")
appAccess.OpenCurrentDatabase "C:\Test\db1.mdb", False

'Run proc in DB1
appAccess.Run "JunkMain"

appAccess.Quit
Set appAccess = Nothing
End Sub

I'd be curious to hear back if this concept works for you.

Nov 13 '05 #4

P: n/a
Salad <oi*@vinegar.com> wrote in message news:<Zssad.13

I added a reference to Northwind. I then opened Northwind and attempted
to create a reference to the main app. It would not do that, and it
complained of a circular reference.

So I tried something else. This concept may do what you want. You'll
need to modify it to your needs.

In DB1, I created the following routines in Module1. I also created a
reference to Northwind.

Sub Junk()
JunkExternal
MsgBox "I'm back again"
End Sub

Public Sub JunkMain()
MsgBox "Hello from Main Module"
End Sub
I opened Northwind and then added the following routines.
Public Sub JunkExternal()
MsgBox "Hello From Module Northwind"
RunAccessSub
End Sub

Public Sub RunAccessSub()
Set appAccess = CreateObject("Access.Application.8")
appAccess.OpenCurrentDatabase "C:\Test\db1.mdb", False

'Run proc in DB1
appAccess.Run "JunkMain"

appAccess.Quit
Set appAccess = Nothing
End Sub

I'd be curious to hear back if this concept works for you.


I understand what you are doing and that would work. The only issue(s)
I have with that approach are:
1. The second module (Northwind in your case) is hardcoded to call the
parent app. It should determine the calling app itself.
2. It would be quite slow; what you are doing is opening a second
instance of Access to run the sub... it would be ideal to just call
the current instance of the parent app from within the addin as it is
already in memory.

Hmmm.. has to be a solution here somewhere.

Thanks for your continuing ideas.

Ju Chao
Nov 13 '05 #5

P: n/a
Ju Chao wrote:
Salad <oi*@vinegar.com> wrote in message news:<Zssad.13
I added a reference to Northwind. I then opened Northwind and attempted
to create a reference to the main app. It would not do that, and it
complained of a circular reference.

So I tried something else. This concept may do what you want. You'll
need to modify it to your needs.

In DB1, I created the following routines in Module1. I also created a
reference to Northwind.

Sub Junk()
JunkExternal
MsgBox "I'm back again"
End Sub

Public Sub JunkMain()
MsgBox "Hello from Main Module"
End Sub
I opened Northwind and then added the following routines.
Public Sub JunkExternal()
MsgBox "Hello From Module Northwind"
RunAccessSub
End Sub

Public Sub RunAccessSub()
Set appAccess = CreateObject("Access.Application.8")
appAccess.OpenCurrentDatabase "C:\Test\db1.mdb", False

'Run proc in DB1
appAccess.Run "JunkMain"

appAccess.Quit
Set appAccess = Nothing
End Sub

I'd be curious to hear back if this concept works for you.

I understand what you are doing and that would work. The only issue(s)
I have with that approach are:
1. The second module (Northwind in your case) is hardcoded to call the
parent app. It should determine the calling app itself.


Yes. You would need to change the functions so you would pass the
calling database name.
2. It would be quite slow; what you are doing is opening a second
instance of Access to run the sub... it would be ideal to just call
the current instance of the parent app from within the addin as it is
already in memory.
Are you planning on lots of errors? :-).

I'm not sure how to do it. I think Michka would be the best person to
answer the question. If he were to step in, you'd get a definitive answer.

Hmmm.. has to be a solution here somewhere.

Thanks for your continuing ideas.

Maybe start another post/thread, and use Michka in the subject line.
Maybe he'd spot it and answer it.
Ju Chao

Nov 13 '05 #6

P: n/a
Salad <oi*@vinegar.com> wrote in message news:<7d****************@newsread1.news.pas.earthl ink.net>...
Ju Chao wrote:
I understand what you are doing and that would work. The only issue(s)
I have with that approach are:
1. The second module (Northwind in your case) is hardcoded to call the
parent app. It should determine the calling app itself.


Yes. You would need to change the functions so you would pass the
calling database name.
2. It would be quite slow; what you are doing is opening a second
instance of Access to run the sub... it would be ideal to just call
the current instance of the parent app from within the addin as it is
already in memory.


Are you planning on lots of errors? :-).

I'm not sure how to do it. I think Michka would be the best person to
answer the question. If he were to step in, you'd get a definitive answer.

Hmmm.. has to be a solution here somewhere.

Thanks for your continuing ideas.


Maybe start another post/thread, and use Michka in the subject line.
Maybe he'd spot it and answer it.


I wonder if Michka does a search for "Michka" on the news groups? In
which case, maybe this will come up on his search:

Michka Michka Michka Michka Michka Michka Michka Michka Michka Michka

:-)

I'll start a new post.

Thanks Salad.

Ju Chao
Nov 13 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.