简体   繁体   English

为什么我的 VBA 代码中出现数据不匹配错误

[英]Why Do i Get A Data Mismatch Error in my VBA Code

I recently added a code to highlight in red the text box that the user did not fill out.我最近添加了一个代码,以红色突出显示用户未填写的文本框。 I also added a code that would alert them with a message box.我还添加了一个代码,用一个消息框提醒他们。 I have this dcount code but when i press the run button to execute the query i get a "Data type mismatch in criteria expression" whenever the user leaves the textbox blank.我有这个 dcount 代码,但是当我按下运行按钮执行查询时,每当用户将文本框留空时,我都会收到“条件表达式中的数据类型不匹配”。 Can you help me with my code?你能帮我写代码吗? Im getting an error on line:我在网上收到一个错误:

If DCount("*", "Final - Union Query 07 & 08") > 0 Then如果 DCount("*", "Final - Union Query 07 & 08") > 0 那么

Private Sub Command2_Click()
 If DCount("*", "Final - Union Query 07 & 08") > 0 Then
    Me!results.Requery
 ElseIf IsNull(Me.master_bill_a.Value) Or (Me.master_bill_a.Value = "") 
 Then
     MsgBox ("All criteria must be filled in the form")
    Me.master_bill_a.BorderColor = vbRed
    DoCmd.GoToControl "master_bill_a"
  ElseIf IsNull(Me.cash_date_a.Value) Or (Me.cash_date_a.Value = "") Then
    MsgBox ("All criteria must be filled in the form")
    Me.cash_date_a.BorderColor = vbRed
    DoCmd.GoToControl "cash_date_a"
  ElseIf IsNull(Me.billing_date_s) Then
    MsgBox ("All criteria must be filled in the form")
    Me.billing_date_s.BorderColor = vbRed
    DoCmd.GoToControl "billing_date_s"
 Else
    MsgBox ("There are no results to display. This may be an overpayment or 
 the wrong information was entered in the form.")

 End If
 End Sub

你需要为那个奇怪的表名加括号:

If DCount("*", "[Final - Union Query 07 & 08]") > 0 Then

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM