如您所说,使用基于临时表的表格是我倾向于输入数据的方式。在 DATA 选项卡下的表单属性中,查找 RECORD SOURCE。然后可以通过数据选项卡再次控制源设置字段。
表单向导实际上应该适合您。
预填充是什么意思?就像有默认文本一样?我使用了很多带有选项的组合框,并确保它们都不是空的,然后有一个按钮可以提交。运行查询以更新主表,然后清空该表。
如果您使用 .mdb 创建一个模块并添加以下代码。(可能必须添加工具>参考。Microsoft DAO 库。)
它将为您运行任何查询。[Param1],[Param2]... 在要动态填写条件的查询中。简单地调用它
fncQueryRun "QueryName", 0
or
fncQueryRun "QueryName", 1, "John Smith"
如果它有一个表单,我会将此代码复制到我创建的每个新数据库中。
我最喜欢的模块代码是:
Public dbTemp As Database, rstTemp As Recordset, tblTemp As TableDef
Public qryTemp As QueryDef, prmTemp As Parameter
Public bQueryError As Boolean, bError3271 As Boolean
Public Function fncQueryRun(ByVal stQueryName As String, ByVal intParamCnt As Integer, _
ParamArray Param() As Variant)
On Error GoTo Err_fncQueryRun
bQueryError = False
Set dbTemp = CurrentDb
DoCmd.SetWarnings False
If intParamCnt = 0 Then DoCmd.OpenQuery stQueryName 'Runs Query
'Parameter Count 0 = Just Runs the Query
If intParamCnt >= 1 Then Set qryTemp = dbTemp.QueryDefs(stQueryName)
If intParamCnt >= 1 Then qryTemp.Parameters![Param1] = Param(0)
If intParamCnt >= 2 Then qryTemp.Parameters![Param2] = Param(1)
If intParamCnt >= 3 Then qryTemp.Parameters![Param3] = Param(2)
If intParamCnt >= 4 Then qryTemp.Parameters![Param4] = Param(3)
If intParamCnt >= 5 Then qryTemp.Parameters![Param5] = Param(4)
If intParamCnt >= 6 Then qryTemp.Parameters![Param6] = Param(5)
If intParamCnt >= 7 Then qryTemp.Parameters![Param7] = Param(6)
If intParamCnt >= 8 Then qryTemp.Parameters![Param8] = Param(7)
If intParamCnt >= 9 Then qryTemp.Parameters![Param9] = Param(8)
If intParamCnt >= 10 Then qryTemp.Parameters![Param10] = Param(9)
If intParamCnt >= 1 Then qryTemp.Execute dbSeeChanges
DoCmd.SetWarnings True
Exit_fncQueryRun:
Set qryTemp = Nothing
dbTemp.Close
Exit Function
Err_fncQueryRun:
bQueryError = True
If Err.Number = 3271 Then
bError3271 = True
Resume Exit_fncQueryRun
ElseIf Err.Number = 3070 Then
Resume Exit_fncQueryRun
Else
MsgBox "Query named " & stQueryName & " - Had error number: " & Err.Number & Chr(10) & Chr(10) _
& Err.Description, , "Query - " & stQueryName & " - Error: " & Err.Number
Resume Exit_fncQueryRun
End If
End Function