0

Dlookup 函数从表中检索单个数据。是否有与此相反的功能?将从表单中选择的数据导出到给定的表。它不能来自 SQL。与Dlookup相反??

4

2 回答 2

0

当然。如果你坚持避免使用 SQL:

  1. 在设计器中创建一个新的更新查询。
  2. =Forms!MyFormName!MyControl用作值(显然用正确的值代替)MyFormNameMyControl
  3. 执行更新查询(手动,或在代码中CurrentDb.Execute "nameOfMyQuery"
于 2022-01-14T14:35:32.937 回答
0

您可以使用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
于 2022-01-14T15:23:42.470 回答