'VBA Excel to Access "Syntax error in From clause"

I am using Windows 10, Office 2021. I am trying to get data from a access table name User.

Application.ScreenUpdating = False
Dim conn As ADODB.Connection
Dim rst As ADODB.Recordset
Dim rfield As ADODB.Field
Dim accdbfile As String
Dim qry As String, i As Integer
Dim n As Long
Dim cnnstr As String
cnnstr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\excel work\shareholder.accdb;"
Set conn = New ADODB.Connection
Set rst = New ADODB.Recordset
conn.ConnectionString = cnnstr

conn.Open
qry = "SELECT Login,Pwd FROM user;"
With rst
    .ActiveConnection = conn
    .Source = qry
    .LockType = adLockReadOnly
    .CursorType = adOpenForwardOnly
End With

**For Each rfield In rst.Fields**
    ActiveCell.Value = rfield.Name
    ActiveCell.Offset(0, 1).Select
Next

Range("A1").Select
Range("A2").CopyFromRecordset rst
rst.Close
Set rst = Nothing
conn.Close
Set conn = Nothing

Getting an error "Syntax error in From Clause". on ** marked line.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source