Solved

Access 2010 VBA -Run-time error '-2147217843 (80040e4d)':  Authenication failed.

Posted on 2013-11-25
1
2,566 Views
Last Modified: 2013-11-25
Can somebody tell me what is causing the following error...

When the following statement gets executed...

With oConn
        .Open (sConn) 'Open the connection.


The following error occurs...
Run-time error '-2147217843 (80040e4d)':

Authenication failed.



The code...
Option Explicit
Sub Import_AccessData()
    Dim oConn As ADODB.Connection
    Dim oRs As ADODB.Recordset, rst2 As ADODB.Recordset
    Dim stDB As String, stSQL1 As String, stSQL2 As String
    Dim sConn As String
    Dim wbBook As Workbook
    Dim wsSheet1 As Worksheet
    Dim lnField As Long, lnCount As Long
    Dim StrDBPath As String
   
     
     'Instantiate the ADO-objects.
    Set oConn = New ADODB.Connection
    Set oRs = New ADODB.Recordset
   ' Set rst2 = New ADODB.Recordset
     
    Set wbBook = ThisWorkbook
    Set wsSheet1 = wbBook.Worksheets("Test")
     
     'Path to the database.
    stDB = "C:\Users\Ritsick\Documents\Red_Compass\DRA\Full Master Sink 5.accdb"
     
     'Create the connectionstring.
    sConn = "Provider=Microsoft.ACE.OLEDB.12.0;" & _
                             "Data Source=" & StrDBPath & ";" & _
                             "Jet OLEDB:Engine Type=5;" & _
                             "Persist Security Info=False;"
       
     'The 1st raw SQL-statement to be executed.
    stSQL1 = "Select Top 1 QUESTIONCODE, REGULATORYANSWER, INPRACTICERESPONSE From vMasterData where QUESTIONCODE = 'GQ-005';"
     
     'The 2nd raw SQL-statement to be executed.
    'stSQL2 = "SELECT * FROM Production_E2"
     
     'Clear the worksheet.
    wsSheet1.Range("A1").CurrentRegion.Clear
     
    With oConn
        .Open (sConn) 'Open the connection.
        .CursorLocation = adUseClient 'Necessary to disconnect the recordset.
    End With
     
    With oRs
        .Open stSQL1, oConn 'Create the recordset.
        Set .ActiveConnection = Nothing 'Disconnect the recordset.
    End With
     
    'With rst2
    '    .Open stSQL2, oConn 'Create the recordset.
    '    Set .ActiveConnection = Nothing 'Disconnect the recordset.
    'End With
     
    With wsSheet1
        .Cells(2, 1).CopyFromRecordset oRs 'Copy the 1st recordset.
    '    .Cells(2, 2).CopyFromRecordset rst2 'Copy the 2nd recordset.
    End With
     
     'Release objects from the memory.
    oRs.Close
    Set oRs = Nothing
    'rst2.Close
    'Set rst2 = Nothing
    oConn.Close
    Set oConn = Nothing
End Sub
0
Comment
Question by:tesla764
1 Comment
 
LVL 119

Accepted Solution

by:
Rey Obrero earned 500 total points
ID: 39674903
you have this

 stDB = "C:\Users\Ritsick\Documents\Red_Compass\DRA\Full Master Sink 5.accdb"

and used, StrDBPath on the connection

   'Create the connectionstring.
    sConn = "Provider=Microsoft.ACE.OLEDB.12.0;" & _
                             "Data Source=" & StrDBPath & ";" & _
                             "Jet OLEDB:Engine Type=5;" & _
                             "Persist Security Info=False;"


change this

 stDB = "C:\Users\Ritsick\Documents\Red_Compass\DRA\Full Master Sink 5.accdb"

with
 stDBPath = "C:\Users\Ritsick\Documents\Red_Compass\DRA\Full Master Sink 5.accdb"
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

No matter the version of Windows you are using, you may have some problems with Windows Search running too slow or possibly not running at all. Before jumping into how you can solve this issue, just know there are many other viable alternative deskt…
In this article we discuss how to recover the missing Outlook 2011 for Mac data like Emails and Contacts manually.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

705 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now