ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   object variable or with variable not set (https://www.excelbanter.com/excel-programming/359572-object-variable-variable-not-set.html)

ina

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


Bob Phillips[_6_]

object variable or with variable not set
 
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)

"ina" wrote in message
ups.com...
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




ina

object variable or with variable not set
 
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


ina

object variable or with variable not set
 
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



All times are GMT +1. The time now is 01:23 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com