Why is this EVENT not cancelling?

mahmed1

Well-known Member
Joined
Mar 28, 2009
Messages
2,302
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hi All,

I have written this afterUpdate event

For some reason when i set the txtBal.setfocus it starts that event again but i thought the enable event would have cancell the event while it resets the focus

Thank You

Here is the code

Code:
Private Sub txtAmt_AfterUpdate()
    txtAmt = Format(txtAmt, "£#,##0.00")
    If txtBal.Value = "" Or txtAmt.Value = "" Then
        MsgBox "Both Balance and Amount fields need to be filled in to proceed further", vbOKOnly, "Update All Fields"
        Exit Sub
    ElseIf txtBal.Value < txtAmt.Value Then
        MsgBox "Balance has to be greater than Amount", vbOKOnly, "INVALID INPUT"
        txtBal.Value = ""
        txtAmt.Value = ""
        Application.EnableEvents = False
        txtBal.SetFocus
        Application.EnableEvents = True
        Exit Sub
    Else
        txtNoPmt = txtBal.Value / txtAmt.Value
    End If
End Sub
 
Excel Options > Add-Ins, Manage: select Excel Add-Ins from the drop-down, press Go.
 
Upvote 0

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Hi Rory,

I have a slight formatting problem.

In my form, if i enter a date say 01/10/2014 (Uk date) whem it transfers this to the cell it displays as 10/01/2014. The cells are formatted as dd/mm/yyyy

I have even tried to format in code and this does not work.

ws.Range("wkDate").Value = Format(txtDte.Value, "dd/mm/yy")

1) How can i get around this

2) What validation code can i have to ensure that anything in that date text box has to be a date entered and no text, plain number and date only entered in format dd/mm/yy and a correct date also so not allowing 32/14/14 etc

I tried to start with adding this

If wkFrm.txtDte.Value <> "" AND IsDate(wkFrm.txtDte.Value) AND (THE FORMAT IS LIKE "DD/MM/YY") AND (IT IS A CORRECT VALID DATE) THEN
Run code
End if
 
Upvote 0
You should start a new thread as that's completely unrelated to the rest of this.

Anyway, use CDate:
Code:
ws.Range("wkDate").Value = CDate(txtDte.Value)
 
Upvote 0

Forum statistics

Threads
1,214,643
Messages
6,120,702
Members
448,980
Latest member
CarlosWin

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