Solved

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

Posted on 2013-11-25
1
2,765 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
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…

734 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