I am trying to print the selected value from a query in vb6 this is my code
dim query as string
dim stsstring as string
dim rs as adobd.recordset
query = "select status from x where y='"& randomString &"'"
set rs = mainmodule.dbutils.dbconnection.connection.execute(query)
set rs = nothing
stsstring = rs.fields("status")
msgbox stsstring
i get error here
stsstring = rs.fields("status")
with message: Object variable or with block variable not set
Thanks in advance!
CodePudding user response:
do this
dim query as string
dim stsstring as string
dim rs as adobd.recordset
query = "select status from x where y='"& randomString &"'"
set rs = mainmodule.dbutils.dbconnection.connection.execute(query)
if not rs.EOF then
stsstring = rs("status").value
end if
msgbox stsstring
CodePudding user response:
You've set rs to nothing before trying to read the status field from it. Re-order your code to read:
'...
stsstring = rs.fields("status")
set rs = nothing
msgbox stsstring