IT Knowledge Base

~ Without sacrifice, there can be no victory ~

發佈日期:

如何在Microsoft Access中‧使用VBA執行SQL SELECT命令

早兩天,有朋友問到在Access中‧用VBA執行SQL SELECT找尋,本來Access一早已經有SQL來過濾數據庫內資料,也不明白為甚麼要這樣做,反正有要求,也找一下資料。

Option Compare Database
Public Sub filter1()
Dim db As DAO.Database, rec As DAO.Recordset
Dim list(500) As String
Dim i As Integer
Set db = CurrentDb
Set rec = db.OpenRecordset("SELECT * FROM Jobs WHERE JobCat='ENGINEERING'")
i = 0
While Not rec.EOF
list(i) = rec![JobCode]
i = i + 1
rec.MoveNext
Wend
For j = 0 To i - 1
MsgBox (list(j))
Next j
rec.Close
db.Close
End Sub

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *