473,396 Members | 1,998 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Error accessing data from Access through Excel

I am trying to get data from Access through a SQL query from Excel via
VBA: but i get an error of "Run Time Error '-2147467259 (800040005)':
Method 'Open' of object '_Recordset' failed"

I have no idea why this is having an error, it is crashing at the line
(any ideas? thanks):
rsData.Open szSQL, connecto, adOpenForwardOnly, adLockReadOnly,
adCmdText

I have the following code:
================================================== =
Public Sub PlainTextQuery()

Dim rsData As ADODB.Recordset
Dim szConnect As String
Dim szSQL As String

Dim connecto As ADODB.Connection
szConnect = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=H:\user\Le\MSRB Daily Data\testDB.mdb;"

Set connecto = New ADODB.Connection

szSQL = "SELECT * FROM Current WHERE Current.CUSIP='005482F82';"

Set rsData = New ADODB.Recordset
connecto.Open szConnect
rsData.Open szSQL, connecto, adOpenForwardOnly, adLockReadOnly,
adCmdText
If Not rsData.EOF Then
Sheet1.Range("A2").CopyFromRecordset rsData
rsData.Close
Sheet1.UsedRange.EntireColumn.AutoFit
Else
MsgBox "Error: No records returned.", vbCritical
End If

If CBool(rsData.State And adStateOpen) Then rsData.Close
Set rsData = Nothing
End Sub
==================================================

Nov 13 '05 #1
0 1424

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: James Bird | last post by:
Hello In order to perform a hetrogeneous join (I think that's what they're called) between MySQL and another database, I've created an Access database containing linked tables from each...
17
by: Ange T | last post by:
Hi there, I'm having pain with the VB behind an Access form. The form is used to create reports in Excel based on the details entered in the form. This has always worked without error on my...
4
by: Polly | last post by:
I had a macro that ran a parameter query and created and opened an Excel file with the system date as part of the file name, but I had to change the file name by hand. So I converted the macro to...
2
by: Kumar | last post by:
Hi Folks, I have a question regarding my windows c# application. This application just reads MS Excel file and puts the data in to sql server database. In that excel file ,it has one named cell...
1
by: sk | last post by:
Please forgive me if the same topic is already posted. But i havent found I have got an error while accessing the excel file as below. Can somebody reply if there is a solution Access is denied....
0
by: jd_12345 | last post by:
Windows XP Pro SP2 Excel 2003 SP2 IBM DB2 Personal Edition accessing a DB2 database on an AIX server via the DB2 ODBC driver I am accessing an external DB via MS Excel using Data-->Import...
0
by: Ducknut | last post by:
Hi all, Thanks in advance, I have form in an access db (Access 2000) that users can use to (hopefully) import a raw .txt file into access. The user clicks a button and a FileDialog opens to select...
2
by: hakkatil | last post by:
Hi to all, I have a page that inserts excel sheet to access database. I am using asp. What I want to do is to check the inserting record if it is in the database. Basicly checking the dublicate...
11
by: fniles | last post by:
One of our application uses VB6 and Access97 database. Another application uses VB.NET 2005. This morning for about 15 seconds when the application tries to read either a query or a table from the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.