0

谁能指出一个可以基于一个表单创建多个记录(在单个表中)的 Access 表单的示例?

扩展:我们正在记录有关给定日期在项目上花费的时间的信息。我们有一个单一表单的请求,允许用户在一个表单上输入给定一周中 5(或 7)天的数据。他/她会从日历控件中选择一周,从列表框中选择一个项目,然后输入最多 7 个数字来表示该周花费的时间。

我确实检查了似乎不适用的问题 5294128 和问题 8070706,这似乎暗示这只能在 VBA 中完成(不使用 GUI)。有什么选择吗?

谢谢。

4

1 回答 1

1

这些线上的东西应该适合。这是一个带有子表单的未绑定表单。

形式

您可以从表单向导中获取表单类型

在此处输入图像描述

要正常工作,您将需要一些代码,例如:

Private Sub cmdGo_Click()
Dim rs As DAO.Recordset
Dim sSQL As String
Dim sSDate As String
Dim sEDate As String

    sSDate = "#" & Format(Me.txtStartDate, "yyyy/mm/dd") & "#"
    sEDate = "#" & Format(Me.txtStartDate + Me.txtNoDays, "yyyy/mm/dd") & "#"

    sSQL = "SELECT * FROM MyTable WHERE DataDate Between " & sSDate _
        & " AND " & sEDate

    Set rs = CurrentDb.OpenRecordset(sSQL)

    If rs.RecordCount < Me.txtNoDays Then
        AddRecords sSDate, sEDate
    End If

    Me.DataSubform.Form.RecordSource = sSQL
End Sub



Sub AddRecords(sSDate, sEDate)
''Uses counter table with integers from 0 to
''highest required number
''Another useful table is a calendat table, which would
''save some work here.

    sSQL = "INSERT INTO MyTable (DataDate) " _
        & "SELECT AddDate FROM " _
        & "(SELECT " & sSDate _
        & " + [counter.ID] AS AddDate " _
        & "FROM [Counter] " _
        & "WHERE " & sSDate _
        & "+ [counter.ID] Between " & sSDate _
        & " And " & sEDate & ") a " _
        & "WHERE AddDate NOT In (SELECT DataDate FROM MyTable)"

    CurrentDb.Execute sSQL, dbFailOnError
End Sub
于 2012-04-09T15:14:35.450 回答