Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Connect through Word 2000

Status
Not open for further replies.

eveCalypso

Programmer
Apr 29, 2003
134
GB
Good Day All,

Could anyone give me advice on how best to connect to my SQL Server 2000 DB through VBA code in Word?
There will be an existing ODBC for other software connecting to the same DB, but I want to make sure I am using the best and most efficient way.
Helpfile mentions ADO, OLE DB etc. (in which case, which references would be apt to use?)

Any advice would be welcome,
Regards,
EvE
 
ADO:

Reference used: Microsoft ActiveX Data Objects 2.5 Library

Dim sConnStr As String
Dim cnConn As ADODB.Connection

Sub OpenDB()
sConnStr = "DRIVER={SQL Server};SERVER=ServerName;UID=user;PWD=password;DATABASE=DatabaseName"
Set cnConn = New ADODB.Connection
With cnConn
.ConnectionString = sConnStr
.CommandTimeout = 600
.ConnectionTimeout = 0 '600
.CursorLocation = adUseClient
.Open
End With
End Sub
Sub CloseDB()
cnConn.Close
End Sub
 
Ok, so this is the preffered way.
Thank you very much, I tried it and it works fine!
Regards,
EvE
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top