2016-05-17 5 views
0

オンクリック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 

End Subの

答えて

0

前に何か他のものに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 
関連する問題