我有一個連續的形式,我想通過我的VBA腳本中的sql select語句填充。我似乎無法做到這一點:填充訪問表格通過sql在vba
sel = "Select * from table1 where a = 10;"
Set SQL = db.OpenRecordset(sel)
SQL.Requery
我有一個連續的形式,我想通過我的VBA腳本中的sql select語句填充。我似乎無法做到這一點:填充訪問表格通過sql在vba
sel = "Select * from table1 where a = 10;"
Set SQL = db.OpenRecordset(sel)
SQL.Requery
爲什麼不把你的select指令放在窗體的recordsource屬性中?
Me.recordsource = "Select * from table1 where a = 10;"
如果你的腳本是在形式的程序之一,或
myForm.recordsource = "Select * from table1 where a = 10;"
如果你的腳本是一個獨立的模塊
中如果你想使用記錄,而不是隻設置RecordSource
(在Philippe Grondier's answer已經建議等),你也可以這樣做:
Set Me.Recordset = db.OpenRecordset("select ...")
我必須承認,設置RecordSource
是「標準方法」(尤其是如果您已經有一條SQL語句並希望使用它填充表單),但我仍然想要展示此替代解決方案。
我通常用它來填充由函數返回的Recordset的表單。
完全正確,這也是我這樣做的方式,雖然我係統地使用ADODB而不是DAO記錄集。 – 2012-02-07 18:11:55
是的,我也是(我們使用Access作爲SQL Server前端) – 2012-02-07 18:18:20