Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2016-10-19
9
Medium Priority
?
142 Views
Last Modified: 2016-11-07
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
0
Comment
Question by:Iver Erling Arva
  • 4
  • 3
  • 2
9 Comments
 
LVL 36

Assisted Solution

by:ste5an
ste5an earned 2000 total points (awarded by participants)
ID: 41849828
It's  x = r![USER_NAME] or x = r.Fields("USER_NAME").
1
 
LVL 18

Expert Comment

by:xtermie
ID: 41849852
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.
0
 

Author Comment

by:Iver Erling Arva
ID: 41849945
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
0
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

 
LVL 36

Accepted Solution

by:
ste5an earned 2000 total points (awarded by participants)
ID: 41849961
Yup, kinda typo. It's myRecord![UserName] or myRecord.Fields("myRecord").
0
 

Author Comment

by:Iver Erling Arva
ID: 41849969
That worked just fine! Thanks!

Brgds
IVer
0
 

Author Comment

by:Iver Erling Arva
ID: 41849973
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
0
 
LVL 36

Assisted Solution

by:ste5an
ste5an earned 2000 total points (awarded by participants)
ID: 41849983
Yup, cause For Each is the wrong approach. You need a classic loop:

Do While Not myRecord.Bof And Not myRecord.Eof
  x = myRecord![USER_NAME]
  'Do something with x...
  myRecord.MoveNext
Loop

Open in new window

0
 

Author Comment

by:Iver Erling Arva
ID: 41849989
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
0
 
LVL 18

Expert Comment

by:xtermie
ID: 41876860
solution provided by Expert
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
Windows Explorer let you handle zip folders nearly as any other folder: Copy, move, change, and delete, etc. In VBA you can also handle normal files and folders, but zip folders takes a little more - and that you'll find here.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question