Results 1 to 4 of 4

Thread: MsgBox if TextBox is not empty
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    Board Regular
    Join Date
    Jun 2016
    Posts
    118
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default MsgBox if TextBox is not empty

    Hello,

    I have a userform with some textboxes and command buttons (one of them, "cmdClose")

    I need to code the following scenario
    If I click "cmdClose" and the textamount is greater than Zero, pop up msgbox with vbYesNo, if I click Yes, close the userform, else, do nothing
    And if txtamount is Zero or null, close the userform without msgbox

    I have the following code that works if the txtamount is greater than Zero, but if txtAmount is empty it does nothing

    Code:
    Private Sub cmdClose_Click()
    If Me.txtAmount.Value > 0 Then
    
    
    result = MsgBox("Are you sure?", vbYesNo + vbCritical, "Closing POS")
    If result = vbYes Then
    Unload Me
    Else
    End If
    End If
    End Sub

  2. #2
    MrExcel MVP
    Moderator
    Fluff's Avatar
    Join Date
    Jun 2014
    Location
    Chippenham
    Posts
    28,209
    Post Thanks / Like
    Mentioned
    471 Post(s)
    Tagged
    47 Thread(s)

    Default Re: MsgBox if TextBox is not empty

    Try
    Code:
    If Val(Me.txtAmount.Value) > 0 Then
    - Posting Data try one of these tools
    - Posting guidelines, forum rules and terms of use
    - Read the FAQs

    Running Office 365 on Win 10

  3. #3
    Board Regular
    Join Date
    Jun 2016
    Posts
    118
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: MsgBox if TextBox is not empty

    It works the same,
    Still if the txtamount is 0 or empty, the form doesn't close

  4. #4
    MrExcel MVP
    Moderator
    Fluff's Avatar
    Join Date
    Jun 2014
    Location
    Chippenham
    Posts
    28,209
    Post Thanks / Like
    Mentioned
    471 Post(s)
    Tagged
    47 Thread(s)

    Default Re: MsgBox if TextBox is not empty

    oops missed that bit, try
    Code:
    If Val(Me.txtAmount.Value) > 0 Then
       If MsgBox("Are you sure?", vbYesNo + vbCritical, "Closing POS") = vbNo Then Exit Sub
    End If
    Unload Me
    - Posting Data try one of these tools
    - Posting guidelines, forum rules and terms of use
    - Read the FAQs

    Running Office 365 on Win 10

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •