Addins with Application Event.

Hi BOB members,
I was trying to code an addin which responds for any application event. But for some reason I’m not getting it to work. I was searching this forum and tried changing my code as suggested but I’m lost. Can somebody please post the code for a simple addin which can just display a message box when an application event (like after refresh)? and I can get it started from there… If you don’t want to post it here, you can email me at koushik7@gmail.com. I really appreciate your help. I am breaking my head with this issue.

Thanks

Koushik


koushik7777 (BOB member since 2004-07-05)

Take a look at this thread, it should work for you.

Have a great night!


MayhewM :us: (BOB member since 2003-10-22)

Here’s a simple snippet:

Option Explicit

Dim WithEvents BOApp As busobj.Application

Private Sub Document_Open()
    Set BOApp = busobj.Application
End Sub

Private Sub BOApp_DocumentAfterRefresh(ByVal Doc As busobj.IDocument)
    MsgBox "Application level after refresh event occured"
End Sub

It’s similar to what Michael referenced. The key is creating the BOApp object including the WithEvents parameter. That’s what allows BusObj to “watch” for the application level events.


Dwayne Hoffpauir :us: (BOB member since 2002-09-19)

I have a similar addin which is coded in the “thisdocument” , but I’m trying to send it to BCA. I guess to send it to BCA, should all the routines which are “private” should they be turned to “public”? because when I select the “action” , “custom macro” and select the .rea file from the “macros in:” drop down, I dont see any routines if they are private. Please suggest your thoughts


broadcast (BOB member since 2004-11-18)

Let’s make sure we are thinking the same. First, an add-in has to be installed on the BCA server(s). It can’t be “sent” like a regular document. To schedule a document using a “custom macro” from the add-in, the add-in has to be installed both on your workstation and the BCA server. When scheduling, you choose from the workstation add-in, and you will get a warning that reminds you that the add-in must also exist on the BCA server.

That said, it does make sense that the macro would need to be public. My suggestion though, is that such “custom macros” should be in their own module, not the ThisDocument module. The example in the previous post was regarding events, not “stand alone” procedures. As long as your module does not have the “Option Private Module” declaration at the top, the procedures will be visible without the need for the Public keyword. In addition to the ThisDocument module, I usually create two modules … one with Option Private Module for “my stuff” and one without for the “end user stuff.”


Dwayne Hoffpauir :us: (BOB member since 2002-09-19)

Please find below my psedo code…


Option Explicit
Private WithEvents objBOApp As Application

Sub Document_Open()
Set objBOApp = Application
End Sub

Private Sub objBOApp_DocumentAfterRefresh(ByVal Docum As IDocument)

****Email stuff ****

End Sub

I do understand(still learning) addins are not similar to regular macros, I wrote the above code in a sample document in it’s “thisdocument” module and saved it as email.rea. I guess now when I schedule a document to BCA with email.rea I still have to select “custom macro and refresh” as the actions, so when i select custom macro and select "email.rea’ from “macros in” drop down, it displays email.rea!open() and I did select that. I guess that’s the procedure. but my question is how do you include this addin in your BCA server? I read from another post saying “if you have this rea saved in your “VBA addins” folder of your BCA server it should work”. is that the process? if not please let me know how to include my addin in my BCA server.

Thanks again
P.S:

  1. we have just one node in our cluster
  2. when i try the same code as a macro instead of an addin, and send the document to BCA it works.

broadcast (BOB member since 2004-11-18)

Broadcast, I think you are still confusing *.rea (add-ins) with macros. They are two different animals even though they share the same VBA editor. Macros are generally stand-alone programs that work within a single document. Whether it’s BusObj, Excel or MS Access, it doesn’t matter. Add-ins are programs that are run in the background of BO, Access or Excel (just to name a few). These programs give specific instructions to be executed for all documents, not a single document. Do a search on google.com for macros and add-ins, you will find more there.

As for your situation of an Add-in to be run on the BCA server, Dwayne has given you some very good information. The add-in must be installed (loaded) locally (tools -> add-ins) into memory. If the you want the add-in to run with BCA, then it has to be installed on every server which has a BCA process running.

Dwayne, correct me if I’m wrong. If he runs the report using a local module then he doesn’t have to have anything on the server except VBA, is that correct? Of course, the stipulation would be that interactive has to be turned off or BCA will hang if an error message occurs or the VBA asks for a prompt. Any additional thoughts Dwayne?

Have a great day.


MayhewM :us: (BOB member since 2003-10-22)

:yesnod:


Dwayne Hoffpauir :us: (BOB member since 2002-09-19)

Thanks for all your clarifications… I guess I understand what your saying… Just to clarify… now I have a addin .rea file in my BCA server(we have just one BCA server). So what you mean is… I have to open Business Objects on my server and go to tools, addin and select the .rea file and i’ll be all set to schedule for BCA right?

Thanks again


broadcast (BOB member since 2004-11-18)