Dlookup 函式從表中檢索單個資料。是否有與此相反的功能?將從表單中選擇的資料匯出到給定的表。它不能來自 SQL。與Dlookup相反??
uj5u.com熱心網友回復:
當然。如果你堅持避免使用 SQL:
- 在設計器中創建一個新的更新查詢。
=Forms!MyFormName!MyControl用作值(顯然用正確的值代替)MyFormName。MyControl- 執行更新查詢(手動,或在代碼中
CurrentDb.Execute "nameOfMyQuery")
uj5u.com熱心網友回復:
您可以使用RecordsetClone作為源和DAO來復制記錄。
然后,用滑鼠記錄選中的記錄,呼叫類似這樣的函式:
Option Compare Database
Option Explicit
Public SubSelHeight As Integer
Public SubSelTop As Integer
Public Function GetSelectedFormRecords()
Dim Index As Long
Dim Form As Form
Dim Records As DAO.Recordset
Dim Copyset As DAO.Recordset
' Get the form and its recordset.
Set Form = Me ' or a subform: Me!NameOfSubformControl.Form
Set Records = Form.RecordsetClone
Set Copyset = CurrentDb.OpenRecordset("Select * From YourCopyTable")
' Move to the first record in the recordset.
Records.MoveFirst
' Move to the first selected record.
Records.Move SubSelTop - 1
For Index = 1 To SubSelHeight
' MsgBox Records!Id.Value
' Copy record.
Copyset.AddNew
Copyset.Field1.Value = Records.FieldX.Value
Copyset.Field2.Value = Records.FieldY.Value
Copyset.Field3.Value = Records.FieldZ.Value
' More fields.
Copyset.Update
Records.MoveNext
Next
Records.Close
Copyset.Close
End Function
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Const EmpiricMaxX As Single = 255
Debug.Print "Mouse X:", X
If X < EmpiricMaxX Then
' Mouse click on record selector.
MsgBox "Select"
End If
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
SubSelTop = Me.SelTop
SubSelHeight = Me.SelHeight
End Sub
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/412567.html
標籤:
上一篇:PowerShell腳本的輸出
