Solved

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

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Microsoft Office Picture Manager was included in Office 2003, 2007, and 2010, but not in Office 2013. Users had hopes that it would be in Office 2016/Office 365, but it is not. Fortunately, the same zero-cost technique that works to install it with …
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…

776 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