Avatar of Iver Erling Arva
Iver Erling Arva
Flag for Norway asked on

Using ADODB connects ok, but get "Object doesn't support this property or method"

See my sample code below. I can connect, and all looks good until I get the run-time errormessage when trying to get USER_NAME from r in line 11.

Sub testSql()
    Dim myConnection, myRecord, x, password
    password = InputBox("Passord: ")
    Set myConnection = CreateObject("ADODB.Connection")
    myConnection.Open "Driver={Microsoft ODBC for Oracle};" & "Server=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS =(PROTOCOL=TCP)(HOST = 10.5.159.184)(PORT = 1541)))(CONNECT_DATA=(SERVICE_NAME=tiaqat)));" & "Uid=ive;" & "Pwd=" & password & ";"
    Set myRecord = CreateObject("ADODB.recordset")
    Sql = "SELECT * FROM TOP_USER"
    myRecord.Open Sql, myConnection
    For Each r In myRecord.Fields
       x = r.USER_NAME
    Next
End Sub

Open in new window

Then I am getting a 438-Object doesn't support this property or method-error. I am able to connect and do all sorts of stuff with the same connect string when I use e.g. PL/SQL-developer...

Thx!

Brgds
IVer
Microsoft ExcelOracle DatabaseVBA

Avatar of undefined
Last Comment
Anastasia D. Gavanas

8/22/2022 - Mon
SOLUTION
ste5an

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Anastasia D. Gavanas

The x variable in your code will be a Field object. A field object does not have an id property hence the error. I suspect that user name is actually the name of the fields you want to use. Hence your code should look like ste5an's suggestion

You could also try changing your open to

myConnection.Open "SELECT USER_NAME FROM TOP_USER", db  
...
Server.URLEncode(myConnection("USER_NAME"))
...
and make your code smaller and only include the fields you need, andnever send unencoded data directly from the DB.
Iver Erling Arva

ASKER
ste5an:

Thanks, but

x = r![USER_NAME] gives me the following error:

Run-time error 450: Wrong number of arguments or invalid property assignment

x = r.Fields("USER_NAME")  gives me the following error:

Run-time error 438: Object doesn't support this property or method.

xtermie:

Thanks, encoded data is fine, but first I need to be able to get something back from the db.
I am not sure I understand your myConnection.Open line. Where do I put the connection details? And as I told you, I AM able to connect. If I put in another password, the database responds with wrong username and/or password, so that seem to be ok.

If I do a
SELECT USER_NAME FROM TOP_USER in PL/SQL Developer it works. The query here is just a simple sample anyway to test that I actually can do it this way. So far no luck, though.

Brgds
IVer
ASKER CERTIFIED SOLUTION
ste5an

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Iver Erling Arva

ASKER
That worked just fine! Thanks!

Brgds
IVer
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
Iver Erling Arva

ASKER
But the loop seems to just find the first record, though. It should be hundreds in that file. Do I need to do some sort of fetch between each?

Brgds
IVer
SOLUTION
ste5an

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Iver Erling Arva

ASKER
ste5an:

Yes, thanks! I just figured that out myself while waiting for your answer ;-)

Great to have such good helpers around!

ALl the best from
IVer
Anastasia D. Gavanas

solution provided by Expert
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.