我有一个带有 project_ID 字段组合框和其他几个字段的 MS Access 表单。一旦用户选择了 project_ID 字段,表单上的大部分后续字段都会自动填充。我正在尝试在表单上添加一个字段,该字段不仅基于 project_ID 还基于 Trans_ID 显示信息。问题是我希望 Trans_ID 成为表单上的一个文本框,用户可以在其中简单地输入 Trans_ID,然后在另一个文本框中显示 Error_DTL_1 字段。这是我到目前为止生成的 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
Dim VarErrorDTL 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
VarErrorDTL = DLookup("[Error_DTL_1]", "[Project_DTA_REV_T]", "[project_ID] = " & VarComboKey And "[Trans_ID] = forms![Quality Risk Assessment]!me.stTransID")
Me.txtErrorDTL = VarErrorDTL
End Sub
“End Sub”之前的两行是我攻击这段代码的尝试。但是每次我在表单上的 Project_ID 组合框中进行选择时,都会收到错误消息“运行时错误 13,类型不匹配”。
任何人都可以帮忙吗?