我正在尝试使用表单字段来检查表列值以预先验证查询以运行这是我的代码,但是我遇到了运行时错误。
' Set Warnings
DoCmd.SetWarnings False
If Forms!FrmCopyRoutingMenu!TextTarget = tblQuoteSection1Lines!tblQuoteMstrID Then
MsgBox ("Quote Section 1 Already Started! Please Copy Individual Sections.")
ElseIf Forms!FrmCopyRoutingMenu!TextTarget = Table!tblQuoteSection2Lines!tblQuoteMstrID Then
MsgBox ("Quote Section 2 Already Started! Please Copy Individual Sections.")
ElseIf Forms!FrmCopyRoutingMenu!TextTarget = Table!tblQuoteSection3Lines!tblQuoteMstrID Then
MsgBox ("Quote Section 3 Already Started! Please Copy Individual Sections.")
ElseIf Forms!FrmCopyRoutingMenu!TextTarget = Table!tblQuoteSection4Lines!tblQuoteMstrID Then
MsgBox ("Quote Section 4 Already Started! Please Copy Individual Sections.")
ElseIf Forms!FrmCopyRoutingMenu!TextTarget = Table!tblQuoteSection5Lines!tblQuoteMstrID Then
MsgBox ("Quote Section 5 Already Started! Please Copy Individual Sections.")
Else
答案 0 :(得分:2)
您想检查TextTarget中的值是否在每个表的ID字段中的任何位置?这有用吗?
Dim target As String
Dim Found As Boolean
target = Forms!FrmCopyRoutingMenu!TextTarget
Found = False
For i = 1 To 5
If DCount("tblQuoteMstrID", "tblQuoteSection" & i & "Lines", "tblQuoteMstrID = '" & target & "'") > 0 Then
MsgBox ("Quote Section " & i & " Already Started! Please Copy Individual Sections.")
Found = True
End If
Next i
If Not Found Then
'code to run query goes here
End If