我目前正在尝试从Microsoft Access数据库(.mdb)中查询表之一,然而,当我尝试执行SELECT * FROM myTable
时,它会出现"用户定义类型未定义"的错误。请问原因是什么?
以下是我的示例代码:
Private Sub CommandButton1_Click()
Dim db As DAO.Database
Dim dbPath As String
Dim aQuery As String
Dim pword As String
Dim rs As DAO.Recordset
dbPath = ThisWorkBook.Path & "\Database.mdb"
pword = "password"
aQuery = "SELECT * FROM myTable"
Set db = Access.DBEngine.Workspaces(0).OpenDatabase(dbPath, True, False, ";PWD=" & pword)
Set rs = db.Execute(aQuery)
rs.MoveFirst
MsgBox rs.Fields(0)
End Sub