有没有办法自动填充 MS Access 表单中的字段?假设用户从表单上的特定组合框中进行选择,是否可以根据 PK 自动选择表单上的其他字段?
我想补充一点,要自动填充的字段将来自各种表。
***修正
在组合框中选择特定记录后,我需要返回多个值。有人可以帮忙吗?多个值将来自返回如下值的查询:
ID Code Count
24 TST 4
24 BPB 7
24 SSS 10
在表单中,组合框将选择 ID 号。一旦我选择了 24 的 ID 号,我想返回来自名为 Project_Error_Final 的查询的所有 3 条记录(在此示例中,有 3 个值要返回,但我希望查询返回 ID = 24 的任何记录)。我到目前为止的 VBA 代码是:
Private Sub cboProjectID_Change()
Dim VarComboKey As Integer
Dim VarObjective As Variant
Dim VarStartDate As Variant
Dim VarEndDate As Variant
Dim VarRiskCategory As Variant
Dim VarTarDatSet As Variant
Dim VarErrorCount As Variant
Dim VarErrorCode As Variant
VarComboKey = Me.cboProjectID.Value
VarObjective = DLookup("[Objective]", "[Project_HDR_T]", "[Project_ID] = " & VarComboKey)
Me.txtObjective = VarObjective
VarStartDate = DLookup("[Start_Date]", "[Project_HDR_T]", "[Project_ID] = " & VarComboKey)
Me.txtStartDate = VarStartDate
VarEndDate = DLookup("[End_Date]", "[Project_HDR_T]", "[Project_ID] = " & VarComboKey)
Me.txtEndDate = VarEndDate
VarRiskCategory = DLookup("[Risk_Category]", "[Project_HDR_T]", "[Project_ID] = " & VarComboKey)
Me.txtRiskCategory = VarRiskCategory
VartxtTarDatSet = DLookup("[Targeted_Dataset]", "[Project_Targeted_Dataset]", "[Project_ID] = " & VarComboKey)
Me.txtTarDatSet = VartxtTarDatSet
VarErrorCount = DLookup("[Count_Error_Codes]", "[Project_Error_Final]", "[project_ID] = " & VarComboKey)
Me.txtErrorCount = VarErrorCount
VarErrorCode = DLookup("[ErrorCode]", "[Project_Error_Final]", "[project_ID] = " & VarComboKey)
Me.txtErrorCode = VarErrorCode
End Sub
有问题的值是 VarErrorCount 和 VarErrorCode。在上面的 VBA 代码中,只返回一个值。但是,一旦选择了 ID 组合框字段,我正在寻找要在我的表单中返回的多个 VarErrorCount 和 VarErrorCode 值。在此特定示例中,VarErrorCode 应返回“TST”、“BPB”和“SSS”。VarErrorCount 应返回相应的 VarErrorCode 值:“4”、“7”、“10”