you don't need the "new" keyword...and it is recommend you don't use "new"
anway....
'An example DAO vs ADO recordset loop, you'll see how similar they are:
'--- begin DAO ---
Dim rst As dao.Recordset
Set rst = CurrentDb.OpenRecordset("select * from contacts")
Do While rst.EOF = False
Debug.Print rst!FirstName
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
'--- end DAO ---
'--- begin ADO ---
Dim rs As ADODB.Recordset
set rs = new ADODB.Recordset ' use the new in code...not at dim
time....
rs.Open ("select * from contacts"), CurrentProject.Connection
Do While rs.EOF = False
Debug.Print rs!FirstName
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
Of couse...in the above example, we are using the built-in connection object
for ADO....
you could deifne that conenciton object....
Dim cn As ADODB.Connection, rs As ADODB.Recordset
Set cn = CurrentProject.Connection
Set rs = New ADODB.Recordset
With rs
rs.Open "MyTable", cn, adOpenDynamic, adLockOptimistic, adCmdText
If Not .EOF Then
.MoveFirst
Do Until .EOF
Debug.Print !MyField
.MoveNext
Loop
End If
.Close
End With
Set rs = Nothing
Set db = Nothing
Of couse, to connect to sql server...you need to go
cn.Open "Provider=sqloledb;" & _
"Data Source=myServerName;" & _
"Initial Catalog=myDatabaseName;" & _
"User Id=myUsername;" & _
"Password=myPassword"
You don't mention what kind of external data source you are talking
about......
....perhahaps a extrenal mdb database?
oConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=c:\somepath\myDb.mdb;"