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
"Ang" wrote in message
...
http://www.codeproject.com/KB/cs/C__..._Mailmerg.aspx
Dear all,
I found a sample code which we don't need to create a datasource file
for mailmerge, we can directly get the data from DSN. However, how can I
get the data directly from SQL server 2005? Can anyone show me the code
of this part? Many Thanks.