Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 11th, 2006, 01:44 AM
Authorized User
 
Join Date: Apr 2006
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
Default run-time error -2147467259 (80004005)

Hi all,

I would like to add data from an access query into excel with this code but it prompts me with this error:

Run time error -2147467259 (80004005)
Automation error
Unspecified error

this is the code I found on the internet.
Could someone have look where it is failing, im new with VBA and dont have clue.

Option Explicit

Sub Execute_StoredQuestion_Dataimport()
    Dim cnt As ADODB.Connection
    Dim rst As ADODB.Recordset
    Dim stDB As String, stSQL As String, stConn As String
    Dim wsSheet As Worksheet

    Set cnt = New ADODB.Connection
    Set rst = New ADODB.Recordset
    Set wsSheet = ThisWorkbook.Worksheets(1)




    stDB = ThisWorkbook.Path & "\test.mdb"

     'Since the database is passwordprotected we need to
     'add the password to get access to it.
    stConn = "Microsoft.Jet.OLEDB.4.0;" _
    & "Data Source=" & stDB

     'The name of the stored question is placed between the brackets.
    'stSQL = "[Access_Question]"

    wsSheet.Range("A1").CurrentRegion.Clear
    cnt.Open stConn
    rst.Open stSQL, cnt

    wsSheet.Cells(2, 1).CopyFromRecordset rst

    rst.Close
    Set rst = Nothing
    cnt.Close
    Set cnt = Nothing
End Sub







Similar Threads
Thread Thread Starter Forum Replies Last Post
Insert Query Error & Run-Time Error 3022 DavidWE Access 1 July 31st, 2008 11:17 AM
runtime error '-2147467259 (80004005) sonal Excel VBA 0 August 13th, 2007 07:06 AM
Run-time '-2147467259 (80004005)' Arsi Excel VBA 0 August 6th, 2007 04:00 PM
runtime error '-2147467259(80004005) denkidude Visual Basic 2005 Basics 1 March 16th, 2007 06:34 AM
run time error -2147467259(80004005) JohnRS4 Pro VB 6 1 June 12th, 2006 01:44 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.