I am trying to return a recordset from access to excel with an ado connection. The VBA code works fine on my home computer, but at my office the code returns:
run-time error '-2147217911 (80040e09)': Record(s) cannot be read; no read permission on TableName.
The database does not have a password, the only difference is that a logon password is required to use access (before any database is opened) . Could this possibly be the problem? If so, is there a way to work around this?
Here is the code:
[vba]
Const ConnectionString As String = _
"Provider=Microsoft.Jet.OLEDB.4.0;" + _
"Data Source=C:\Users\Owner\Desktop\ADO.mdb;" + _
"Persist Security Info=False"
Dim Connection As ADODB.Connection
Set Connection = New ADODB.Connection
Connection.ConnectionString = ConnectionString
Connection.Open
Dim Recordset As Recordset
Dim SQL As String
Dim RowsAffected As Long
SQL = "SELECT Resolution.CutOff, Resolution.LoanNumber, LoanToInvestor.Investor, ServNbrToAccount.[P&IAccount], ResolutionDetail.DueDate, ResolutionDetail.RPayment, ResolutionDetail.RRate, ResolutionDetail.RSrvRate, ResolutionDetail.RBegBal, ResolutionDetail.RCurt, ResolutionDetail.CPayment, ResolutionDetail.CRate, ResolutionDetail.CSrvRate, ResolutionDetail.CBegBal, ResolutionDetail.CCurt, Resolution.ResolutionID " & _
"FROM (ServNbrToAccount INNER JOIN ((InvestorToServNbr INNER JOIN LoanToInvestor ON InvestorToServNbr.Investor = LoanToInvestor.Investor) INNER JOIN Resolution ON LoanToInvestor.[BAC Loan] = Resolution.LoanNumber) ON ServNbrToAccount.ServNbr = InvestorToServNbr.ServNbr) INNER JOIN ResolutionDetail ON Resolution.ResolutionID = ResolutionDetail.ResolutionID " & _
"WHERE (((Resolution.ResolutionID)=2));"
'code fails here
Set Recordset = Connection.Execute(SQL, RowsAffected, CommandTypeEnum.adCmdText)
sh3.Range("A2").CopyFromRecordset Recordset
[/vba]