我想使用ADO記錄集來創建基於現有表的新表。然後我想設置新表作爲我的表單的記錄source.i知道我可以創建一個查詢並將查詢設置爲我的表單的記錄源,但是它如果我不想使用這種方法可能嗎?我希望表單的記錄源僅在表單加載時才存在。這是我所做的,但仍然無法將表單的記錄源設置爲我的記錄集。如何使用ADO記錄集基於現有表創建新表並將記錄集(新表)設置爲表單的記錄源?
Private Sub Form_Load()
Dim cnn As ADODB.Connection
Set cnn = CurrentProject.Connection
Dim rst As New ADODB.Recordset
rst.ActiveConnection = cnn
Dim mySql As String
'create tblfrmQryOnHold based on tblOnHold
mySql = "SELECT tblDisposition.ID, tblDisposition.DateRecorded, tblDisposition.OrderNo, tblDisposition.ArticleNo, "
mySql = mySql & "tblDisposition.Description, tblDisposition.Process, tblDisposition.Defects, tblDisposition.RefNo, "
mySql = mySql & "tblDisposition.PostedBy, tblDisposition.Status, tblDisposition.Attachment, tblDisposition.Engineer, "
mySql = mySql & "tblDisposition.Remarks, tblDisposition.ReviewClose, tblDisposition.ScrapNo, tblDisposition.HoldbackNo, "
mySql = mySql & "tblDisposition.ProductionRemarks, tblDisposition.HoldbackQuantity, tblDisposition.HoldbackNum INTO "
mySql = mySql & "frmQryOnHold FROM tblDisposition;"
rst.Open mySql
'set form frmOnHold record source to form frmQryOnHold
Forms![frmOnHold].RecordSource = frmQryOnHold
End Sub
我得到這個錯誤「當對象關閉時不允許操作」,這個錯誤引用哪個對象?
爲什麼選擇ADO? DAO對MS Access更好。 – Fionnuala 2013-03-20 11:50:53