It is not only possible, it is quite easy too. Check out these resources:
http://word.mvps.org/faqs/interdev/ControlXLFromWord.htm
http://word.mvps.org/FAQs/InterDev/ControlWordFromXL.htm
This is what I use personally:
http://word.mvps.org/FAQs/InterDev/FillListBoxFromXLDAO.htm
If you use this technique, you will have to create a UserForm (called
'UserForm1') and a ListBox (called 'ListBox1') and a CommandButton (called
'CommandButton1').
When you double-click on the CommandButton, you need to have code such as:
Private Sub CommandButton1_Click()
ListBox1.BoundColumn = 1
ActiveDocument.Variables("Tracking_Number").Value = ListBox1.Value
ListBox1.BoundColumn = 2
ActiveDocument.Variables("First_Name").Value = ListBox1.Value
ListBox1.BoundColumn = 3
ActiveDocument.Variables("Last_Name").Value = ListBox1.Value
ActiveDocument.Fields.Update
UserForm1.Hide
End Sub
Also, you need to have code such as:
Private Sub UserForm_Initialize()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim NoOfRecords As Long
' Open the database
Set db = OpenDatabase("C:\Test\Book1.xls", False, False, "Excel 8.0")
' Retrieve the recordset
Set rs = db.OpenRecordset("SELECT * FROM `myDatabase`")
' Determine the number of retrieved records
With rs
.MoveLast
NoOfRecords = .RecordCount
.MoveFirst
End With
' Set the number of Columns = number of Fields in recordset
ListBox1.ColumnCount = rs.Fields.Count
' Load the ListBox with the retrieved records
ListBox1.Column = rs.GetRows(NoOfRecords)
' Cleanup
rs.Close
db.Close
Set rs = Nothing
Set db = Nothing
End Sub
Finally, in your Word document, or Word Template, you need to go to: Insert
Field > DocumentVariable...then name the variable...such as
Tracking_Number, or First_Name, or Last_Name...
Hope that helps!
Regards,
Ryan--