View Single Post
  #4 (permalink)  
Old February 14th, 2005, 09:13 AM
mmcdonal mmcdonal is offline
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

What do you mean by "accessing" a SQL server? What do you want to do there?

Do you want to use a DSN, or ADO?

I use these connections to write data to SQL server. This may get you started if that is what you need:

'==========
strUserName = "yourSQLusername"
strPassword = "yourSQLpassword"
Const adOpenStatic = 3
Const adLockOptimistic = 3
Const adUseClient = 3

Set objConnection = CreateObject("ADODB.Connection")
Set objRecordset = CreateObject("ADODB.Recordset")
objConnection.Open "DSN=YourDSNName;", strUserName, strPassword
objRecordset.CursorLocation = adUseClient
objRecordset.Open "SELECT * FROM tblYourTable" , objConnection, adOpenStatic, adLockOptimistic

   objRecordset.AddNew
   objRecordset("Field1") = "YourData1"
   objRecordset("Field2") = "YourData2"
   '...
   objRecordset("Fieldn") = "YourDatan"
   objRecordset.Update

objRecordset.Close
objConnection.Close
'==========

HTH

mmcdonal
Reply With Quote