View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
ina ina is offline
external usenet poster
 
Posts: 120
Default object variable or with variable not set

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