The first thing you need to do is set a reference to the microsoft ActiveX Data Object. You don't have to do this and you can create objects but you will not have the intellisense drop downs and the application itself is not as efficient.
Dim cnMyConn As ADODB.Connection
Dim rsMyRS As ADODB.Recordset
Dim strMySQL As String
'create the connection object
Set cnMyConn = CreateObject("adodb.connection" 'open the connection object using a DSN entry
'you could also just pass it your connection string
cnMyConn.Open "DSN=Test2000"
'set up your sql string
strsql = "Select * From tblTest"
'create you recordset object
Set rsMyRS = cnMyConn.Execute(strsql)
'you now have a recordset object and you can do what you want with it
'the following just loops through the recordset and prints out the two
'fields to the immediate window
With rsMyRS
Do While Not .EOF
Debug.Print .Fields("Test1"
Debug.Print .Fields("Test2"
.MoveNext
Loop
End With
'close the recordset object
rsMyRS.Close
'release the objects
Set rsMyRS = Nothing
Set cnMyConn = Nothing
This is just a basic example but should get you started with playing around with your data in SQL Server. Hope this helps you out and just holler if you have any other questions.....
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.