请帮我处理下面的代码。表示运行时错误3265,并将这一行显示为error:
表("Logs"提取)。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:UsersChristosDesktopSample.accdb"
AccessFile = "\MNLDCPWFIS01CorpStrat-PublicLEADSCONVERSION WORKING DATABASESCRM_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
哦,我知道了。这是表头的位置。我错了,对不起