MsgBox Showing Twice

Pacman52

Active Member
Joined
Jan 29, 2009
Messages
380
Office Version
  1. 365
Platform
  1. Windows
Hi all - I'm struggling to work out why a response MsgBox keeps popping up twice before moving on to the next box would be depending on the response being either yes or no. I'm sure its something simple that wrong with the code I've written but for some reason just can't see what's wrong so would be grateful if someone with better knowledge than me could work out what I'm doing wrong or missing.


The problem is with the last part of the sub and the msgbox

VBA Code:
 MsgReply = MsgBox("Does this expense relate to a date period (i.e. between two dates)?", vbQuestion + vbYesNo, "Expense Date Required")

The full code in the sub is:

VBA Code:
Private Sub txbExpAmount_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Dim MsgReply As VbMsgBoxResult

    If Not IsNumeric(txbExpAmount.Value) And txbExpAmount.Value > "" Then

        MsgBox "It looks like you've entered a text value. Please only enter a numeric value greater than 0.", vbExclamation, "Invalid Entry"
        Cancel = True
        txbExpAmount.Value = ""
        txbExpAmount.SetFocus
        txbExpAmount.SelStart = 0
        txbExpAmount.SelLength = Len(txbExpAmount.Value)
        txbExpAmount.BackColor = RGB(204, 255, 255)

    ElseIf txbExpAmount.Value = "" Then

        MsgBox "It looks like you've left this box empty. Please only enter a numeric value greater than 0. ", vbExclamation, "Invalid Entry"
        Cancel = True
        txbExpAmount.Value = ""
        txbExpAmount.SetFocus
        txbExpAmount.BackColor = RGB(204, 255, 255)

    ElseIf txbExpAmount.Value = "0" Then

        MsgBox "The total expense amount needs to be a value greater than 0. Please only enter a numeric value greater than 0.", vbExclamation, "Invalid Entry"
        Cancel = True
        txbExpAmount.Value = ""
        txbExpAmount.SetFocus
        txbExpAmount.BackColor = RGB(204, 255, 255)

    Else
    
    If txbExpAmount.Value > "0" Then

        MsgReply = MsgBox("Does this expense relate to a date period (i.e. between two dates)?", vbQuestion + vbYesNo, "Expense Date Required")
        

    If MsgReply = vbYes Then
    
        txbExpDate.Enabled = False
        txbPeriodFrom.SetFocus
        txbExpAmount.Value = Format(txbExpAmount.Value, "£0.00")

    Else

        txbExpDate.Enabled = True
        txbExpDate.SetFocus
    
    End If
    End If
    End If

End Sub

Many thanks for any replies Paul
 
Hi Dave - yes I did follow your code as shown and didn't alter it in anyway.

To be honest it may of been my fault anyway as I'd made so many changes to the original code I'd written it may of happened because of something in there I'd missed. I do have a old back up I can refer to so once I get this one working I will try your code again but I'm under a bit of pressure now to get this done but I will post back and let you know.

Paul
 
Upvote 0

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Hi Dave sorry for the delay in responding to this thread.

Just to let you know I did try the code again on an old copy of my workbook and again it failed so I decided to try it on a new simplified userform as a test with just a few relevant textboxes and it did work so there must be something I had in the original code that was causing the problem.

In the end I re-evaluated the actual form and what info was needed and removed what was not - as usual I was over complicating the process but thankfully now it is all working fine.

Thanks again for the code though and for taking the time to respond.
 
Upvote 0
No worry glad you have managed to resolve appreciate your feedback

Dave
 
Upvote 0

Forum statistics

Threads
1,222,830
Messages
6,168,507
Members
452,194
Latest member
Lowie27

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top