首页 > 解决方案 > excel vba运行时报错3265项在请求的名称或序号对应的集合中找不到

问题描述

请帮助我使用下面的代码。表示运行时错误 3265 并将这一行显示为错误:

Sheets("提取的日志").Cells(11, i + 1) = rs.Fields(i - 3).Name

即使我使用“Select * From table”仍然存在同样的问题。需要你的帮助谢谢!我被代码问题困住了。

错误信息是:运行时错误 3265 项目在与请求的名称或序号对应的集合中找不到

'Disable screen flickering.
Application.ScreenUpdating = False

Range("E12:L1048576").ClearContents

'Specify the file path of the accdb file. You can also use the full path of the file like:
'AccessFile = "C:\Users\Christos\Desktop\Sample.accdb"
AccessFile = "\\MNLDCPWFIS01\CorpStrat-Public\LEADS\CONVERSION WORKING DATABASES\CRM_INC.accdb"

'get active user
Set OL = CreateObject("outlook.application")
Set olAllUsers = OL.Session.AddressLists.Item("All Users").AddressEntries
User = OL.Session.CurrentUser.Name
Set oentry = olAllUsers.Item(User)
Set oExchUser = oentry.GetExchangeUser()

Set rs = Nothing

'Set the name of the query you want to run and retrieve the data.
strQuery1 = "select Task_Number, Short_Description, Task_Status, Task_Complexity, Assignment_Group, Assigned_To, Created_Date " & _
"from INC_CRM where Requestor_Email = '" & oExchUser.PrimarySmtpAddress & "' order by Created_Date desc; "
    
On Error Resume Next
'Create the ADODB connection object.
Set con = CreateObject("ADODB.connection")
'Check if the object was created.
If err.Number <> 0 Then
    MsgBox "Connection was not created!", vbCritical, "Connection Error"
    
End If
On Error GoTo 0

'Open the connection.
con.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & AccessFile

On Error Resume Next
'Create the ADODB recordset object.
Set rs = CreateObject("ADODB.Recordset")
'Check if the object was created.
If err.Number <> 0 Then
    'Error! Release the objects and exit.
    Set rs = Nothing
    Set con = Nothing
    'Display an error message to the user.
    MsgBox "Recordset was not created!", vbCritical, "Recordset Error"
    Exit Sub
End If
On Error GoTo 0
     
'Set thee cursor location.
rs.CursorLocation = 3 'adUseClient on early  binding
rs.CursorType = 1 'adOpenKeyset on early  binding

'Open the recordset.
rs.Open strQuery1, con

'Check if the recordset is empty.
If rs.EOF And rs.BOF Then
    'Close the recordset and the connection.
    rs.Close
    con.Close
    'Release the objects.
    Set rs = Nothing
    Set con = Nothing
    'Enable the screen.
    Application.ScreenUpdating = True
    'In case of an empty recordset display an error.
    MsgBox "There are no records in the recordset!", vbCritical, "No Records"
    Exit Sub
End If

'Copy the recordset headers.
For i = 0 To rs.Fields.Count + 3
    Sheets("Extracted Logs").Cells(11, i + 1) = rs.Fields(i - 3).Name
Next i

'Write the query values in the sheet.
 Sheets("Extracted Logs").Range("E12").CopyFromRecordset rs

'Close the recordset and the connection.
rs.Close
con.Close


'Release the objects.
Set rs = Nothing
Set con = Nothing

'Adjust the columns' width.
'Columns("A:L").AutoFit
'Sheets("Extracted Logs").Range("J2", "J50000").NumberFormat = "mm/dd/yyyy hh:mm:ss AM/PM"
'Sheets("Extracted Logs").Range("I2", "I50000").NumberFormat = "mm/dd/yyyy hh:mm:ss AM/PM"

'Enable the screen.
Application.ScreenUpdating = True

标签: excelvba

解决方案


哦,好的,我现在明白了。它是我的表格标题的定位。我的错误对不起


推荐阅读