Hi all, So after hours of trying to workout myself why I can't get this to work I've finally given up trying and would be really grateful if someone could tell me what I'm doing wrong please.
So in the code below I'm trying to exit the textbox 'textboxInvoiceDate' and show the msgbox asking has the invoice been paid. If the response is Yes then I need to be able to set the focus to the 'textboxDateInvoicePaid' if the response is no I want to disable the 'textboxDateInvoicePaid' and textboxPaymentMethod and move the focus to the next relevant box (textboxInvoiceDetails).
The problem I'm getting is the msgbox asking if the invoice has been paid appears as expected but the focus stays in the textbox and the msgbox appears again I then tab out of the textbox again and the msgbox again shows - its like the textbox isn't exiting initially and re-setting the focus back to itself.
Could anyone advise what I'm missing here or doing wrong.
Many thanks Paul
So in the code below I'm trying to exit the textbox 'textboxInvoiceDate' and show the msgbox asking has the invoice been paid. If the response is Yes then I need to be able to set the focus to the 'textboxDateInvoicePaid' if the response is no I want to disable the 'textboxDateInvoicePaid' and textboxPaymentMethod and move the focus to the next relevant box (textboxInvoiceDetails).
The problem I'm getting is the msgbox asking if the invoice has been paid appears as expected but the focus stays in the textbox and the msgbox appears again I then tab out of the textbox again and the msgbox again shows - its like the textbox isn't exiting initially and re-setting the focus back to itself.
Could anyone advise what I'm missing here or doing wrong.
Many thanks Paul
VBA Code:
Private Sub textboxInvoiceDate_Enter()
textboxInvoiceDate.BackColor = RGB(204, 255, 255)
End Sub
Private Sub textboxInvoiceDate_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
If Not IsDate(textboxInvoiceDate) Then
MsgBox "Your entry is not recognised as a date. Please only enter a date in the correct format e.g. 'DD/MM/YYYY'", vbExclamation, "Invalid Entry"
Cancel = True
textboxInvoiceDate = ""
textboxInvoiceDate.BackColor = RGB(204, 255, 255)
textboxInvoiceDate.SetFocus
Else
textboxInvoiceDate = Format(CDate(textboxInvoiceDate), "DD/MM/YYYY")
End If
End Sub
Private Sub textboxInvoiceDate_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Dim MsgReply1 As VbMsgBoxResult
If textboxInvoiceDate.Value = "" Then
Cancel = True
MsgBox "You must enter the date of the invoice.", vbExclamation, "Date Required"
textboxInvoiceDate.SetFocus
textboxInvoiceDate.BackColor = RGB(204, 255, 255)
Else
If textboxInvoiceDate.Value >= "" Then
MsgReply1 = MsgBox("Has this invoicealready been paid?", vbQuestion + vbYesNo, "Payment Method")
If MsgReply1 = vbYes Then
textboxDateInvoicePaid.Enabled = True
textboxDateInvoicePaid.SetFocus
textboxPaymentMethod.Enabled = True
textboxInvoiceDate = Format(CDate(textboxInvoiceDate), "DD/MM/YYYY")
textboxInvoiceDate.BackColor = RGB(255, 255, 255)
Else
textboxDateInvoicePaid.Enabled = False
textboxPaymentMethod.Enabled = False
textboxInvoiceDetails.SetFocus
End If
End If
End If
End Sub