Solved

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

Posted on 2013-11-25
1
2,736 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 120

Accepted Solution

by:
Rey Obrero (Capricorn1) 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As with any other System Center product, the installation for the Authoring Tool can be quite a pain sometimes. This article serves to help you avoid making these mistakes and hopefully save you a ton of time on troubleshooting :)  Step 1: Make sur…
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…

713 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