BusinessObjects Board

adding a command to Tools menu

i’m trying to provide a custom functionality.
when i add a new command popup to the tool bar, it appears only when i open a document. users wants this command without opening a doc.

i’m tryin to add this command to the Tools Menu, but again it appears only when i open a document…

how do i make my command appear without opening a doc…
[/code]


prasad :india: (BOB member since 2002-08-19)

Just a thought – if you are adding it on a document open event, but don’t delete it with a document close, you could fanagle something like when you run BO a dummy report opens, and it’s on document open event also closes itself… you know? So it would flash up real quick, close, and the user would have their command…

Might be a little :crazy_face: though!


JennFisher :us: (BOB member since 2002-06-25)

Turn the document with the code into an add-in (file, save as, and change the filetype to add-in). Then go to Tools, Add-Ins to set the newly created .rea file to open automatically with BusObj.


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

Hello all,

I am facing the same problem, the new menu or new entry only appears once a document is open.

Unfortunately, the code I am using is already in a .REA which is already opened so the above solution does not work neither.

I will continue to search for a solution and will post it in this thread if I find one


fguionne :fr: (BOB member since 2002-08-16)

This is code I use to add a button to the tool bar. I would imagine that adding a command to the Tools menu bar would be similar.

You need to add the button to the tool bar in the Application Open event and not in a Document Open.

See BO document Introduction to Developer Suite pp. 53-57.

Use the add-in approach that Dave suggests.

In BO VBA, create a new project. In the project, you’ll need a class module (I call mine AppRefClass) with the following in it:

Public WithEvents boApp As Application

Next, create a code module (I call mine modMacros) with the following in it:

Public AppRef As New AppRefClass
Public gbtnTool As CmdBarControl

Sub Enable_App_Events()
Set AppRef.boApp = Application
End Sub

Sub ToolMacro()
' Do what you need to do
End Sub

Finally, you’ll need to add this to the add-in’s ThisDocument code:

Private Sub Document_Open()
Call Enable_App_Events
Set gbtnTool = Application.CmdBars("Standard").Controls.Add(boControlButton)
With gbtnTool
  .Caption = "Tool"
  .DescriptionText = "Run ToolMacro"
  .TooltipText = "Run ToolMacro"
  .OnAction = ThisDocument.Name & ".rea!modMacros.ToolMacro"
  Application.Clipboard.Clear
  Application.Clipboard.SetData LoadPicture(ThisDocument.Path & "\Tool.bmp")
  .PasteFace
  Application.Clipboard.Clear
End With
End Sub

Private Sub Document_BeforeClose(Cancel As Boolean)
On Error Resume Next  ' ignore run-time errors
gbtnTool.Delete
Set gbtmTool = Nothing
End Sub

Once testing is complete, save it as an rea and add it to the add-ins via Tools->Add-Ins. There is also a way to add the add-in to all users but that’s another discussion.


dirmiger :us: (BOB member since 2002-08-28)

Thank you dirmiger but it does not work. :wah:

Your example is actually working fine but it applies to adding a button in the toolbar not adding a menu entry in the specific CmdBars(2).

When trying to add menu entries rather than adding buttons to other toolbars it works only when a document is opened and not before ( I guess it is a bug or a limitation ).

Although the event DocumentOpen gets correctly fired when loading the .REA ( verified by a MsgBox display ) the code for adding menu entries only gets applied once a “real” document is opened.

Actually moving to a toolbar button rather than a menu entry will give a workaround.

Thank you again for your help. :yesnod:


fguionne :fr: (BOB member since 2002-08-16)

I’m going to have to disagree. The code in this utility successfully adds menu items within CmdBars(2). Is it possible that your issue is because CmdBars(2) is not even displayed by BusObj unless a “real” document is open? Prior to that, CmdBars(1) is displayed. Both CmdBars(1) and CmdBars(2) are named Menu Bar, but only one is displayed at a time, depending on whether a “real” document is open. Maybe your solution is to customize both 1 and 2, so that the new menu item is available in both cases?


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

I’d go with Dwayne’s suggestion of modifying both…


dirmiger :us: (BOB member since 2002-08-28)

Bingo !! :lol:

The menu bar that appears when no document is opened in the interface ( or only REAs ) is in fact Application.CmdBars(1)

while the menu bar that appears once a .rep file is opened is Application.CmdBars(2)

Thanx Dwayne and dirmiger for your help :yesnod: it works fine now.


fguionne :fr: (BOB member since 2002-08-16)

You’re quite welcome. Glad it worked for you.


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

I am trying to create a button on the Standard toolbar. I have used code from this posting.This gave me the functionality that I needed, however for some reason there is an inconsistency in the image pasting on the button that is created. Sometimes it appears and other times it doesn’t. Also the tool bar height is also expanding. Any ideas as to what is going on? Here is the code that I am using.

Thanks!

I created a class module and named it App Ref Class and this code:

Public WithEvents boApp As Application

I created a module call modMacros and this code:

Public AppRef As New AppRefClass
Public gbtnTool As CmdBarControl

Sub Enable_App_Events()
Set AppRef.boApp = Application
End Sub
Sub ToolMacro()
’ Do what you need to do
MainMenu.Show
End Sub

I created a Document_Open() and Document_BeforeClose events and used this code:

Private Sub Document_Open()

Call Enable_App_Events
Set gbtnTool = Application.CmdBars(“Standard”).Controls.Add(boControlButton)
With gbtnTool
.Caption = “Search Metadata”
.DescriptionText = “Search Metadata”
.TooltipText = “Search Metadata”
.OnAction = ThisDocument.Name & “.rea!modMacros.ToolMacro”
Application.Clipboard.Clear
Application.Clipboard.SetData MainMenu.Image2.Picture
(My image 2 is an imbedded image on the MainMenu form)
.PasteFace
Application.Clipboard.Clear
End With

End Sub

Private Sub Document_BeforeClose(Cancel As Boolean)

On Error Resume Next ’ ignore run-time errors
gbtnTool.Delete
Set gbtmTool = Nothing
End Sub


kkerns (BOB member since 2006-04-05)