【问题标题】:On Click command and not adding text when text box is blank当文本框为空白时,单击命令并且不添加文本
【发布时间】:2016-05-17 11:15:26
【问题描述】:

单击时我希望我的按钮在 me.txtAddNote 为空白时不添加文本,并显示一条消息提示用户输入文本或取消。当 me.txtAddNote 有文本时,我希望单击时输入文本。目前,我的代码在这两种情况下甚至在 msgbox 弹出之前都添加了文本。任何帮助表示赞赏,谢谢。

Private Sub cmdAddNote_Click()
Dim LName As String
On Error Resume Next
LName = DLookup("[LNAME]", "[qryEmpDepDes]", "[EMP_NO]='" & Me.txtUserID & "'")
[NOTES] = Date & ": " & Me.txtAddNote & " (" & Me.txtUserID & " " & LName & ")" & vbNewLine & vbNewLine & [NOTES]
Me.txtAddNote = ""
Me.cmdAddNote.Enabled = True
Me.cmdClose.Enabled = True
Me.cmdClose.SetFocus
'5-16-2016 testing blank text box'
  If Me.txtAddNote = "" Then
 If MsgBox("No text is entered. Hit OK to enter text. Hit CANCEL to close out.", vbOKCancel) = vbOK Then
    End If
Else
    DoCmd.Close
End If

结束子

【问题讨论】:

    标签: vba ms-access


    【解决方案1】:

    尝试先检查 txtAddNote 的内容?

    Private Sub cmdAddNote_Click()
    Dim LName As String
    
    If Me.txtAddNote.Text = "" Then
        response = MsgBox("No text is entered. Hit OK to enter text. Hit CANCEL to close out.", vbOKCancel)
        If response = vbOK Then
            ' do whatever you needed
        Else
            Exit Sub    ' Exit the sub if Cancel was clicked
        End If
    End If
    
    On Error Resume Next
    LName = DLookup("[LNAME]", "[qryEmpDepDes]", "[EMP_NO]='" & Me.txtUserID & "'")
    [NOTES] = Date & ": " & Me.txtAddNote & " (" & Me.txtUserID & " " & LName & ")" & vbNewLine & vbNewLine & [NOTES]
    Me.txtAddNote = ""
    Me.cmdAddNote.Enabled = True
    Me.cmdClose.Enabled = True
    Me.cmdClose.SetFocus
    
    DoCmd.Close
    
    End Sub
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-07-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-24
      • 2012-09-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多