Mailmerge getting data in sql server directly

D

Doug Robbins - Word MVP

Here is how to get information from a SQLEXPRESS database

Dim con As New ADODB.Connection
Dim rst As New ADODB.Recordset
Public constring As String

constring = "Provider=SQLOLEDB.1;" _
& "Server=GLOBAL-C66780E6\SQLEXPRESS;" _
& "Database=nameofdatabase;" _
& "Integrated Security=SSPI;" _
& "DataTypeCompatibility=80;"
con.ConnectionString = constring
con.Open
Set rst.ActiveConnection = con
With rst
.Source = "SELECT * FROM Applicants ORDER BY ApplicantName"
For i = 1 To .Fields.Count
lstAppFields.AddItem .Fields(i - 1).Name
Next i
lstApplicants.ColumnCount = .Fields.Count
.Open
i = .RecordCount
lstApplicants.Column = .GetRows(i)
End With
Set rst = Nothing


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

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