2016-05-17 42 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 

末次

回答

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