Hi,
I am trying to edit the code from below mentioned website to suite my requirements.
However, before I could finish editing, I could see few of the code lines are reflecting in red.
I have mentioned 'Code is reflecting in red line below' just above the problematic code.
Can anyone please help me in resolving this. I do not have any idea why these lines are reflecting in red.
https://www.exceltrainingvideos.com/get-data-from-access-database-using-excel-vba/
I am trying to edit the code from below mentioned website to suite my requirements.
However, before I could finish editing, I could see few of the code lines are reflecting in red.
I have mentioned 'Code is reflecting in red line below' just above the problematic code.
Can anyone please help me in resolving this. I do not have any idea why these lines are reflecting in red.
https://www.exceltrainingvideos.com/get-data-from-access-database-using-excel-vba/
Code:
Option Explicit
Sub getDataFromAccess()
'Click on Tools, References and select
'the Microsoft ActiveX Data Objects 2.0 Library
Dim DBFullName As String
Dim Connect As String, Source As String
Dim Connection As ADODB.Connection
Dim Recordset As ADODB.Recordset
Dim Col As Integer
Cells.Clear
'Database path info
'Your path will be different
DBFullName = "\\A\B\C\My Documents\Database4.accdb"
'Open the connection
Set Connection = New ADODB.Connection
'Code is reflecting in red line below
Connect = “Provider=Microsoft.ACE.OLEDB.12.0;”
'Code is reflecting in red line below
Connect = Connect & “Data Source=” & DBFullName & “;”
Connection.Open ConnectionString:=Connect
'Create RecordSet
Set Recordset = New ADODB.Recordset
With Recordset
'Filter Data
'Code is reflecting in red line below
Source = “SELECT * FROM Orders WHERE [Shipper ID] = 3 ”
.Open Source:=Source, ActiveConnection:=Connection
'Write field names
'Code is reflecting in red line below
For Col = 0 To Recordset.Fields.Count – 1
Range(“A1”).Offset(0, Col).Value = Recordset.Fields(Col).Name
Next
'Write recordset
Range(“A1”).Offset(1, 0).CopyFromRecordset Recordset
End With
ActiveSheet.Columns.AutoFit
Set Recordset = Nothing
Connection.Close
Set Connection = Nothing
End Sub