Sub ADOImportFromAccessTable(ByVal DBFullName As String, TableName As String, TargetRange As Range, Optional blFieldNames As Boolean)
Dim intColIndex As Integer
Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset
Set cnn = New ADODB.Connection
cnn.Provider = "Microsoft.Jet.OLEDB.4.0"
cnn.Properties("Data Source") = DBFullName
cnn.Properties("Jet OLEDB:System database") = mdwlocation
cnn.Open UserId:="Admin", Password:=""
Set TargetRange = TargetRange.Cells(1, 1)
Set rst = New ADODB.Recordset
With rst
.Open TableName, cnn, adOpenDynamic, adLockOptimistic
If Not .EOF Then
.MoveFirst
If blFieldNames Then
For intColIndex = 0 To rst.Fields.Count - 1 ' the field names
TargetRange.Offset(0, intColIndex).Value = rst.Fields(intColIndex).Name
Next
TargetRange.Offset(1, 0).CopyFromRecordset rst ' the recordset data
Else: ' No FieldNames
TargetRange.Offset(0, 0).CopyFromRecordset rst ' the recordset data
End If
End If
.Close
End With
Set rst = Nothing
cnn.Close
Set cnn = Nothing
End Sub