object variable or with variable not set

I

ina

Hello :),

I am newbie in vba and this is my connection code but I have a problem
with rs.field I do not have the result of my query.

What can I do?


Sub connection()


Dim rs As ADODB.Recordset
Dim cnx As ADODB.Connection
Dim code As String

Set cnx = New ADODB.Connection


cnx.ConnectionString = {connection}

cnx.Open
'test de connection
If cnx.State = adStateOpen Then
End If

'Set cmd = New ADODB.Command
'Set cmd.ActiveConnection = cnx
'cmd.CommandText = "select * from clients"
'cmd.CommandType = adcomdtext

'Set rs = New ADODB.Recordset
'Set rs.Source = cmd

rs.ActiveConnection = cnx
rs.Open "select * from qrypacfund"

internalcode = rs.Fields(1).Value


Do While Not rs.EOF

code = Fields(1).value


rs.movenext

Loop

rs.Close
cnx.Close

Set cnx = Nothing
Set rs = Nothing

End Sub
Ina
 
B

Bob Phillips

This

code = Fields(1).value

at least should be

code = rs.Fields(1).value


but where is the problem, which line of code?

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)
 
I

ina

yes thanks I understood the problem I commented the set rs ... and I
had a problem with that. a really thank you for you help.

Ina
 
I

ina

yes thanks I understood the problem I commented the set rs ... and I
had a problem with that. a really thank you for you help.

Ina
 

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