VBA美元在用户录入表格P $ pvent空字段 [英] VBA to prevent empty fields in a user-entry form

查看:148
本文介绍了VBA美元在用户录入表格P $ pvent空字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有VBA代码,我现在用的检查在弹出的窗体空白字段的麻烦。在code应该检查窗体上的空白领域,通知用户如果有空白表格,如果没有,添加记录。我有第二个功能,其中保存记录,然后关闭表单。下面是code我使用检查空白:

I am having trouble with VBA coding which I am using to check for blank fields in a pop-up form. The code is supposed to check for blank fields on the form, notify the user if there are blank forms, and if there isn't, add the record. I have a second function which saves the record, then closes the form. Below is the code I am using to check for blanks:

Private Sub Form_BeforeUpdate(Cancel As Integer)

Dim ctrl As Control
Dim strMsg As String

For Each ctrl In Me.Controls

    If ctrl.Tag = "BlkChk" Then
        If IsNull(ctrl) Then
           strMsg = strMsg & "- " & ctrl.Name & vbCrLf
        End If
    End If

Next ctrl

If strMsg <> "" Then
    If vbOK = MsgBox("The following fields require a response:" & vbCrLf & vbCrLf & _
       strMsg & vbCrLf & vbCrLf, _
       vbOKOnly) Then
       Cancel = True

       Me.cboLookup.SetFocus
    End If

End If

End Sub

下面是$ C $下我的添加记录按钮:

Here is the code for my 'add record' button:

Private Sub cmdAddRecord_Click()
On Error GoTo cmdAddRecord_Click_Err

    DoCmd.Save
    DoCmd.Close , ""

cmdAddRecord_Click_Exit:
    Exit Sub

cmdAddRecord_Click_Err:
    MsgBox Error$
    Resume cmdAddRecord_Click_Exit

End Sub

的code中的第一位工作正常,但是当我点击我的添加记录按钮,并执行code我的第二位,它会通知用户两次,然后不保存关闭的形式,不管所有空格都填写与否。我已经通过几个例子网上去了解其他人如何设置它,看看我能实现自己的想法,但它只是不为我工作。我想可能有一些做的'添加记录'code,但我似乎无法弄清楚。我应该如何解决这个问题?我要调整我的编码或者我应该结合所有到一个单一的On_Click()命令?

The first bit of code works fine, but when I click my 'add record' button, and execute my second bit of code, it will notify the user twice, then close the form without saving, regardless if all blanks are filled in or not. I've went through several examples online about how other people have set it up to see if I could implement their ideas, but it's just not working for me. I think it might have something to do with the 'add record' code, but I can't seem to figure it out. How should I approach this problem? should I restructure my coding or should I combine it all into a single On_Click() command?

推荐答案

您使用的不是 MSGBOX()方法正确。试试这个:

You're not using the MsgBox() method correctly. Try this:

If strMsg <> "" Then
   MsgBox "The following fields require a response:" & vbCrLf & vbCrLf & _
       strMsg & vbCrLf & vbCrLf, vbOKOnly

   Me.cboLookup.SetFocus
   Cancel = True

End If

这篇关于VBA美元在用户录入表格P $ pvent空字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆