combobox to another word doc

D

Daniel

Hello

I have a four table in a word document. I need to link all of the comboboxes in the second table of this document to the table in another word document ("Standards.doc") so that the user can make their selection and then after the selection is made a macro will populate another column within the table with the appropriate info. Let me explain..

Current Document....
SAFETY EVALUATIO
# Norm Section - Title Objective Comment(s
*********************************************************************
1 Combobox (input by user) I want linked to combobox (input by user)
2 Combobox (input by user) I want linked to combobox (input by user)
3 Combobox (input by user) I want linked to combobox (input by user)

Reference Documen
Specification ASTM European Interna
Section Description Section Description Section Descriptio
***************************************************************************************
Dropt tes
Impact tes
Edge

I want the combobox to list all of the items in the "Specification" column (excluding the header) and once the user makes a selection, I want the macro to copy the value of the column that will be in ("Light-Yellow") (for each test one of the columns (ASTM, Eurpean, internal will be in light yellow) associated with that specification and paste it in the column entitled "Objective of the current document

Thanking you in advance for your help

Danie
 
W

Word Heretic

G'day Daniel <[email protected]>,

big job, loose spec. The combobox has on onexit you use. If you need
to custom populate the combo use the onentry. The backing macro does a

Dim D as Document
Set D=Documents.Open blah

to open the doc and can then access D.Content.Tables(1) and so on.


Steve Hudson - Word Heretic
Want a hyperlinked index? S/W R&D? See WordHeretic.com

steve from wordheretic.com (Email replies require payment)


Daniel reckoned:
 
D

Doug Robbins - Word MVP - DELETE UPPERCASE CHARACT

A few questions:

Are there only ever 3 items in the Safety Evaluation form?
Are they only ever to be populate with those three specifications are are
there many more to choose from?
Are there entries in each of the ASTM, European and Internal columns for
each specification but only the one in yellow to be used?
Is the Safety Evaluation form a document protected for form?


--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 
D

Daniel P

Steven

I'm quite new at this programming stuff (especially with word), could you possibly elaborate a little more

1. For instance, how can I populate the combobox with the value of the other document information using the the second column of information bu excluding the first two rows (they are headers)? Therefore I want to populate my combobox with the info of cell(3,2) to the cell(LastRow,2)

2. The onexit event, How can I get it to look at the row associate with the entered value selected in the combo box and then return the value of the column in "light-yellow" for that row

Thank you very much for your help

Daniel
 
D

Doug Robbins - Word MVP - DELETE UPPERCASE CHARACT

The following can be used for a combobox as well

This routine loads a listbox with client details stored in a table in a
separate
document (which makes it easy to maintain with additions, deletions etc.),
that document being saved as Clients.Doc for the following code.

On the UserForm, have a list box (ListBox1) and a Command Button
(CommandButton1) and use the following code in the UserForm_Initialize() and
the CommandButton1_Click() routines

Private Sub UserForm_Initialize()
Dim sourcedoc As Document, i As Integer, j As Integer, myitem As Range,
m As Long, n As Long
' Modify the path in the following line so that it matches where you
saved Clients.doc
Application.ScreenUpdating = False
' Open the file containing the client details
Set sourcedoc = Documents.Open(FileName:="e:\worddocs\Clients.doc")
' Get the number or clients = number of rows in the table of client
details less one
i = sourcedoc.Tables(1).Rows.Count - 1
' Get the number of columns in the table of client details
j = sourcedoc.Tables(1).Columns.Count
' Set the number of columns in the Listbox to match
' the number of columns in the table of client details
ListBox1.ColumnCount = j
' Define an array to be loaded with the client data
Dim MyArray() As Variant
'Load client data into MyArray
ReDim MyArray(i, j)
For n = 0 To j - 1
For m = 0 To i - 1
Set myitem = sourcedoc.Tables(1).Cell(m + 2, n + 1).Range
myitem.End = myitem.End - 1
MyArray(m, n) = myitem.Text
Next m
Next n
' Load data into ListBox1
ListBox1.List() = MyArray
' Close the file containing the client details
sourcedoc.Close SaveChanges:=wdDoNotSaveChanges
End Sub

Private Sub CommandButton1_Click()
Dim i As Integer, Addressee As String
Addressee = ""
For i = 1 To ListBox1.ColumnCount
ListBox1.BoundColumn = i
Addressee = Addressee & ListBox1.Value & vbCr
Next i
ActiveDocument.Bookmarks("Addressee").Range.InsertAfter Addressee
UserForm2.Hide
End Sub

The Initialize statement will populate the listbox with the data from the
table and then when a client is selected in from the list and the command
button is clicked, the information for that client will be inserted into a
bookmark in the document. You may want to vary the manner in which it is
inserted to suit our exact requirements, but hopefully this will get you
started.

To make it easy for you, the code has been written so that it will deal with
any number of clients and any number of details about each client. It
assumes that the first row of the table containing the client details is a
header row.


--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 
D

Doug Robbins - Word MVP - DELETE UPPERCASE CHARACT

If there can be a variable number of items on the Safety Evaluation Form,
that means that you will have a variable number of comboboxes on that form.

Are the entries in each Combobox the same?

The need to link an objective to the selection in the combobox based on the
colour of the objective definitely does not simplify this thing. Seems to
me that it would be better to run a macro over the document containing the
Specifications and the ASTM, European and Internal "options" so that you
just had the one "option" for each Specification item.

Finally, I would not say that this is impossible (I would never say that),
but, it's no simple task for someone new to this sort of thing in Word.
However, if the document is not protected, it would appear that you are
using controls from the visual basic toolbox in a Word document. How does
the number of comboboxes get varied?

I would not do it this way at all. Rather, I would create a userform. With
a single combobox and text boxes to allow the user to create each record
consisting of the Norm, Section-Title, Objective and Comment(s) for each
item. Then there would be a button that they could click that would add the
item to a ListBox on the userform. This process would be repeated as
required and when finished, the user would click on another button to dump
all of the data from the listbox into the document.

--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top