Using ADO

G

Guest

Hi
I want to convert my code to ADO, whenever I want to open recordset, i
notice that i must write the following
Dim conn As ADODB.Connection
Dim rst As ADODB.Recordset
Dim strConn As String
strConn = "Provider = Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & CurrentProject.Connection

Set rst = New ADODB.Recordset
With rst
is there any way I can reduce it or?
Thanks n regards
 
R

RoyVidar

Wahab said:
Hi
I want to convert my code to ADO, whenever I want to open recordset,
i notice that i must write the following
Dim conn As ADODB.Connection
Dim rst As ADODB.Recordset
Dim strConn As String
strConn = "Provider = Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & CurrentProject.Connection

Set rst = New ADODB.Recordset
With rst
is there any way I can reduce it or?
Thanks n regards

DAO is probably more effective on Jet tables, so I don't understand
why you wish to switch.

Anyway, to get a readonly forwardonly recordset, you could just do
an execute on the connection, perhaps soemthing like this?

dim rs as adodb.recordset
dim cn as adodb.conection
set cn = currentproject.connection
set rs = cn.execute("select * from table1",,adcmdtext)

or just

set rs = currentproject.connection.execute( _
"select * from table1",,adcmdtext)

Else, something like this?

dim rs as adodb.recordset

set rs = new adodb.recordset
with rs
set .activeconnection = currentproject.connection
.locktype = adlockoptimistic
.cursortype = adopenkeyset
.cursorlocation = aduseclient
.open "select * from table1",,,,adcmdtext
end with

Air Code ...
 
B

Brendan Reynolds

You can do away with your 'conn' variable altogether ...

Dim rst As ADODB.Recordset

Set rst = New ADODB.Recordset
Set rst.ActiveConnection = CurrentProject.Connection

BTW: This seems a very strange time to be switching to ADO. Is there a
reason why you're doing that?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top