0
votes

On Click I want my button to not add text when me.txtAddNote is blank and display a message prompting the user to enter text or cancel. And when me.txtAddNote has text I would like the On Click to enter the text. Currently, my code adds text on both conditions and even before the msgbox pops up. Any help is appreciated, thank you.

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

1

1 Answers

0
votes

Try checking the content of txtAddNote prior to anything else?

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