|
-
Feb 17th, 2013, 06:02 AM
#3
Thread Starter
Lively Member
Re: Run-time error '-2147467249 (80004005)' Method 'Open' of object _Recordset' faile
I tried that, that made no difference :-(
However I re-wrote a separate function for opening the recordset:
Public Function open_recordset(SQL_String As String, Database_Connection As ADODB.Connection, Query_Start As String) As ADODB.Recordset
Set rs = New ADODB.Recordset
rs.Open SQL_String, Database_Connection
Set open_recordset = rs
Field_Count = rs.Fields.Count
My_Array = rs.GetRows()
kolumner = UBound(My_Array, 1)
rader = UBound(My_Array, 2)
For k = 0 To kolumner ' Using For loop data are displayed
Range(Query_Start).Offset(0, k).Value = rs.Fields(k).Name
For R = 0 To rader
Range(Query_Start).Offset(R + 1, k).Value = My_Array(k, R)
Next
Next
rs.Close
Set rs = Nothing
End Function
and it seems to work.
I think possibly the problem was to do with variables, I also added:
Public cn As ADODB.Connection
Public rs As ADODB.Recordset
Anyway, so it works, but I'd be interested to know, if my understanding of why it works is correct, if anyone has a chance to look over my code!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|