Method or Data Member Not Found error, after connecting to Microsoft SQL Server

M

Morris

Hello all!

That's the code:

Public dbsConnect As ADODB.Connection

Public Sub ConnectToDatabase()

Const sSOURCE As String = "ConnectToDatabase"

Dim lAttempt As Long
Dim sConnect As String
Dim sSQL As String
Dim rsData As Recordset

sConnect = "Provider=SQLOLEDB;Data Source=ServerName;User
ID=uid;Password=pwd;"

MsgBox "Opening Connection..."

Set dbsConnect = New ADODB.Connection
dbsConnect.ConnectionString = sConnect
dbsConnect.Open

MsgBox "i'm connected!"

-----
Up to this point everything is fine
----

Sheet1.UsedRange.Clear
sSQL = "SHOW TABLES"

Set rsData = New ADODB.Recordset
rsData.Open sSQL, sConnect, adOpenForwardOnly, adLockReadOnly,
adCmdText
--------------^^^^^^-----------
This is where I get the error - on rsData.Open
But all the samples and manuals I've found use this method, so where
lies the mistake? I'm using Excel 2003
--------------------------------

'ThisWorkbook.Sheets(1).Range("A1").CopyFromRecordset output

MsgBox "Closing Connection..."

dbsConnect.Close

MsgBox "fine"

End Sub

Private Sub CommandButton1_Click()
Call ConnectToDatabase
End Sub
 
M

Morris

Dim rsData As Recordset


I've found the solution:
instead of \Dim rsData As Recordsdet\
I have to declare: \Dim rsData As ADODB.Recordsdet\

And now I can use the 'Open' method freely :)

Thanks for your feedback
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top