Add-In Express and ADO SQL Server databases

Add-in Express™ Support Service
That's what is more important than anything else

Add-In Express and ADO SQL Server databases
Query database with Add-In Express 
agent86




Posts: 14
Joined: 2013-11-16
Delphi 7 Enterprise
Word 2010

Very new Add-In Express user...second day in fact.

I need to query a SQL server database so I can retrieve a list of reports that are stored in the database. I will then write that list of reports to a dropdown in the Word ribbon add-in I am writing. I'm used to using a data module in Delphi, though I could certainly put the database components on the add-in module if that is allowed.

Is it better to do all my database work with VBA and do it in the macro document and just call them with Delphi? Or do my database calls inside the add-in module with Delphi?

Samples or examples would be appreciated.

Thank you...
Posted 18 Nov, 2013 21:26:05 Top
Andrei Smolin


Add-in Express team


Posts: 14980
Joined: 2006-05-11
Hello,

I would start with populating the dropdown. there are two possiblities:
1) the report list is static
2) the report list can change at run time and you need to reflect the changes

#1. In the OnRibbonBeforeCreate event of the add-in module, you read the list and create items (of the TadxRibbonItem type) to populate the dropdown. No problem here.

#2. The only component that you can use is TadxRibbonMenu having TadxRibbonMenu.Dynamic = true. This is due to the fact that Ribbon controls are static from birth and dynamic menu is the only component allowing re-population at run time. Whenever the user expands the menu, TadxRibbonMenu generates the OnCreate event. In this event you re-create the controls to be shown on the menu.

When populating the controls at run time please be aware that quite typically people forget that all Ribbon controls (and items) must have a unique ID that cannot start with a number.

See also:
TadxRibbonControlType
Can a Ribbon Menu be changed after it has been shown/created?
Adding dynamic controls to TadxRibbonSplitButton

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 19 Nov, 2013 03:50:51 Top
agent86




Posts: 14
Joined: 2013-11-16
I did not realize you could not update dropdowns at runtime. Since I want to display a list of the reports from the database that the user can select at runtime and have the item selected viewable like a dropdown, what controls would you suggest I load into the menu? Is there some sample code showing the insertion of those control types into the menu? It must be a control that stays or displays after selection like a dropdown. The control must continue to show the selection like would happen with a dropdown.

I would be open to suggestions if there is a better approach to my problem.
Posted 19 Nov, 2013 13:13:29 Top
Andrei Smolin


Add-in Express team


Posts: 14980
Joined: 2006-05-11
Hello,

If you need to use the Ribbon way, I've described it already. You can try creating a static menu at design time and populate it with controls.

You can also embed a TadxOlForm as demonstrated in the manual, see the PDF file in the folder {Add-in Express}\Docs on your development PC. Since TadxOlForm descends from TForm, you can use any suitable controls on that form.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 20 Nov, 2013 04:10:48 Top
agent86




Posts: 14
Joined: 2013-11-16
So the TadxOlForm is available to use in a Word Add-In?

Does any control we put in a menu become dynamic?
Posted 20 Nov, 2013 09:50:06 Top
Andrei Smolin


Add-in Express team


Posts: 14980
Joined: 2006-05-11
agent86 writes:
So the TadxOlForm is available to use in a Word Add-In?


My bad. I should have used "TadxWordTaskPane" instead of "TaxOlForm".

agent86 writes:
Does any control we put in a menu become dynamic?


No. The only control providing this is TadxRibbonMenu having TadxRibbonMenu.Dynamic = true.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 20 Nov, 2013 10:02:46 Top
agent86




Posts: 14
Joined: 2013-11-16
I'm confused. Maybe I misunderstood your answer. The TadxRibbonMenu is dynamic but the controls we add to it are not dynamic? How is the content of the TadxRibbonMenu "updated" during run-time if the controls we add to the menu are not dynamic?
Posted 20 Nov, 2013 10:11:29 Top
Andrei Smolin


Add-in Express team


Posts: 14980
Joined: 2006-05-11
As explained TadxRibbonMenu having TadxRibbonMenu.Dynamic = true is the only way to have some dynamicality in the Ribbon UI. Still, a dropdown created by the dynamic menu remains a static thing. You cannot modify the list (say, add an item) of the dropdown's items in an arbitrary moment; to modify the list, you'll actually need to recreate the dropdown and its item when the dynamic menu to generate another OnCreate event.

Do I answer your question?

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 20 Nov, 2013 10:31:49 Top
agent86




Posts: 14
Joined: 2013-11-16
So this is what I think you are saying...if I added a dropdown control to the TadxRibbonMenu. Hey wait a minute. A dropdown is not available to pick to drop on the RibbonMenu(?). I assume the dropdown can't be repopulated from a call in the OnCreate event on the RibbonMenu.

What happens in the Word application I am supporting is that the user clicks a button on a custom tab and the report generation program starts. The report generation program is independent of Word. It is started from a "shell execute" process. When the report generation program closes it writes the new report to a sql database, the Word VBA that called the report generation program runs another VBA routine that queries the database and inserts the report into the Word document.

Works sort of like this...

Sub CreateAndInsertNewReport
  Call StartReportProgram
  Call InsertReportIntoWordDocument
End Sub


The new report the user just created needs to appear in the dropdown list from now on or until it is deleted in the other Report Program.

Maybe I can't do what I want. I need to do all this on the ribbon, not in a task pane.
Posted 20 Nov, 2013 11:01:34 Top
Andrei Smolin


Add-in Express team


Posts: 14980
Joined: 2006-05-11
You can try populating a dynamic Ribbon menu with Ribbon buttons. Each of the buttons can open the corresponding report. This will work on the Ribbon if you have less than 1000 reports.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 21 Nov, 2013 10:21:35 Top