Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How do I get data from MySQL ?

124 views
Skip to first unread message

bchin

unread,
Jan 28, 2005, 3:25:02 PM1/28/05
to
Is there a way to get data from a MySQL database? Then can I insert the data
into Word in some non-table format? I want to be able to place some data
within paragraphs of my document.

Leigh

unread,
Jan 28, 2005, 4:26:10 PM1/28/05
to
Sure. In a VBA module, add a reference to "Microsoft ActiveX Data
Objects 2.x Library" (Tools, References). Then in your code, do
something like this:

Sub DataInsert()
Dim loConnection As New ADODB.Connection
Dim loRecordset As New ADODB.Recordset
Dim loRange As Word.Range

loConnection.Open ("MyDsnName")
With loRecordset
Set .ActiveConnection = loConnection
.Open ("SELECT * FROM MyTableName")
Set loRange = Selection.Range.Duplicate
While Not .EOF
loRange.InsertAfter .Fields("MyFieldName") & vbCrLf
.MoveNext
Wend
.Close
End With
loConnection.Close
Set loRange = Nothing
Set loRecordset = Nothing
Set loConnection = Nothing
End Sub

This code assumes you have a Data Source Name called "MyDsnName"
already defined, and that it has a table or view in it called
MyTableName with a field called MyFieldName.

0 new messages