Discussion Locked

How do you add a button to MS Word?

0 helpful
5 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I need a button on MS Word (97-2003) that when you click on it, it will send a query such as

SELECT text from textable;

to the database, and then present a list of texts that when you click on any item, that item gets added to the word document.

Thanks.

Pat

5 replies

by zimonar

To add commands button; Right-click on any toolbar, click Customize and activate the Commands tab, select the desired category and click on Rearrange Commands? button. Check the menu or the toolbar box and select from the arrow drop down list, choose a Control and click on Add? button then close Rearrange Commands and close Customize.
- You can also add tools, choose your desired tool from Customize Toolbars dialog box; activate the Toolbars tab. Check the desired toolbar box and close Customize.
- To restore your toolbar, check the desired toolbar box from the Toolbars tab and click on Reset button and close Customize.

by toivo talikka

If you add a button by recording a macro, for example to add a row to a table, and then go to Tools - Macro, you will be able to edit the Visual Basic code behind the macro.

The article Visual Basic Programmer's Guide at http://www.microsoft.com/technet/prodtechnol/office/office2000/proddocs/opg/part2/ch05.mspx gives you a starting point in your quest. You need to become familiar with Data Access Objects (DAO) or ActiveX Data Objects (ADO).

Do some research and have a look at source code, for example the knowledgebase article "How to programmatically import Outlook items from Access" at http://support.microsoft.com/?kbid=290658, which, even though written for Outlook, you may be able to modify to work in Word.

The MSDN newsgroup word.vba.general at http://msdn.microsoft.com/newsgroups/default.aspx?dg=microsoft.public.word.vba.general may be a good way to get started. There are other forums from where you may find snippets of VBA code.

by wu78754

Thank you for the response. I did get that far before I posted the question.

The problem is, I am not sure which category to select.

Maybe I should reframe the question:

I saw a document that has a customized button.
When that button is clicked on, a query is sent to the Oracle database server (e.g., SELECT texts FROM textlibrary).
Then a list of text is returned and displayed.
When you click on any line on the list, that line of text is added to the Word document.

What I would like to know is to see the info behind that button or to create a button that would do something similar.

Thank you in advance for your help.

Patrick

by sgt_shultz

could be a Word 'form', or a Web page or a linked application...
in Word Help, check out forms, in particular the FORMDROPDOWN field codes...also use 'database' for the search term and maybe you will want to check out using MS Query or build a query in Excel or Access to link into the Word doc...where is this texttable?? on a network? on one computer ? if you know sql maybe you want to go the Web page route...?

by toivo talikka

If you want to see what is behind the button, you need to go to the Macros, as described earlier, and check out the Visual Basic code.

If Oracle is the database product at the back end, the Visual Basic code most likely uses the Open Database Connectivity (ODBC) method to access the database.

Go to Microsoft Visual Basic (Tools - Macro - Visual Basic Editor) and select Help - Microsoft Visual Basic Help. Go to Microsoft Visual Basic Reference - Properties - D - DataSource Property. This entry shows how to set the database to be SQL Server, just to illustrate how databases in general are accessed from Word.

In the same Help context, select Microsoft Word Object Help - Programming Concepts - Accessing Data and Other Applications - Using DAO from Microsoft Word. The example shows how to retrieve records from a table in the Northwind database in Access.

In Microsoft Visual Basic Help, do a search on OpenDataSource. The description of this method shows how you can determine the ODBC connection and query strings, and the last example shows how to access Northwind through ODBC, which you can hopefully modify to suit your Oracle database.

And how to tell Windows that you want to access Oracle? The Microsoft Knowledgebase article "HOW TO: Create a System Data Source Name in Windows XP" at http://support.microsoft.com/default.aspx?scid=kb;en-us;305599 shows how you can set up the connection in Windows XP. You will find 'Microsoft ODBC for Oracle' from the list of drivers under the tab System DSN.

Good luck!

This discussion is closed to new replies.