有人能指出一个Access表单的例子,它可以根据一个表单创建多个记录(在一个表中)吗?
扩展:我们正在记录有关在给定日期花在项目上的时间的信息。我们已经请求单个表单,允许用户在单个表单上输入给定周的5(或7)天的数据。他/她会从日历控件中选择一周,从列表框中选择一个项目,然后输入最多7个数字来表示该周所花费的时间。
我确实检查了问题5294128,这似乎不适用,问题8070706,这似乎暗示这只能在VBA中完成(不使用GUI)。任何替代方案?
感谢。
答案 0 :(得分: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