首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >重复输入警告消息框

重复输入警告消息框
EN

Stack Overflow用户
提问于 2015-11-23 17:50:53
回答 2查看 126关注 0票数 1

当输入重复号码时,我正在尝试显示一个消息框。如果两个字段匹配、Source和Voucher_Number,则此表中的副本将为。

源被格式化为文本。

Voucher_Number被格式化为数字

下面是我的代码:

代码语言:javascript
复制
If (IsNull(DLookup("Source", "tblInvoiceLog", "Source ='" & 
Me.Source.Value & "'"))) And _
(IsNull(DLookup("Voucher_Number", "tblInvoiceLog", "Voucher_Number ='" &
Me.Voucher_Number.Value & "'"))) Then

Else
MsgBox "Duplicate Entery!" & Chr(13) & Chr(10) & "Please Use the Next
Available Consecutive Voucher Number", vbInformation, "Required"
End If

End Sub

我得到了:

运行时错误3464

除了解决这个问题之外,我最终想要做的是在消息框中返回原始条目的Vendor_Name中字段的值。

谢谢你的帮助,任何人都可以

EN

回答 2

Stack Overflow用户

发布于 2015-11-23 18:41:29

您可以尝试将DLookup返回值具体转换为字符串,以确保将苹果与苹果进行比较。如果仍然有错误,请使用F8执行该错误,并在s1stLookup和s2ndLookup上悬停以查看为变量分配了哪些值。

代码语言:javascript
复制
Dim s1stLookup as String
Dim s2ndLookup as String

'Specifically cast the DLookup return values as Strings
s1stLookup = CStr(DLookup("Source", "tblInvoiceLog", "Source ='" & Me.Source.Value & "'"))
s2ndLookup = CStr(DLookup("Voucher_Number", "tblInvoiceLog", "Voucher_Number ='" & Me.Voucher_Number.Value & "'"))

If (IsNull(s1stLookup)) And (IsNull(s2ndLookup)) Then
  '... Presumably some code here
Else
  MsgBox "Duplicate Entery!" & vbCrLF & _
    "Please Use the Next Available Consecutive Voucher Number", _
    vbInformation, "Required"
End If
票数 1
EN

Stack Overflow用户

发布于 2015-11-23 23:16:14

目前,您正在分别测试这两个值。但

如果两个字段匹配、Source和Voucher_Number,则此表中的副本将为。

因此,您需要测试两个值是否存在于同一个记录中,方法是将这两个条件与DLookup调用放在一起并放入其中。如果[Vendor_Name]是一个副本,那么您可以直接查找这个字段:

代码语言:javascript
复制
Dim sVendor as String
sVendor = Nz(DLookup("Vendor_Name", "tblInvoiceLog", _
    "Source = '" & Me.Source & "' AND Voucher_Number = " & Me.Voucher_Number), "")

If sVendor <> "" Then
    MsgBox "Duplicate entry of vendor '" & sVendor & "'."
Else
    ' ok, no dupe
End If

我发现最好总是在Nz()中使用DLookup(),这样我就可以处理字符串而不是变体。空字符串表示没有结果。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33877356

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档