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
 
It depends. CInt will return an Integer (i.e. whole number between -32768 and 32767).
 
Upvote 0

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Thank you

lastly i guess the default type for a text box is String?

is there a way i could Dim the textbox like a normal variable to say double rather than using the cdbl in the code?

Would this be a good way of doing it?

and say i dim s as string and then used cdbl(s) would this convert the data type to double temporarily throughout the code or would it change the data type to double so that variable if used later on in code, will be double and not string?
 
Upvote 0
A text box is precisely that - a text box. It's always text.

cdbl doesn't convert the variable you pass to it - it returns a value of the specified type. So CDbl(s) doesn't affect the s variable at all.
 
Upvote 0
Hi Rory

if i understand correctly.. Cdbl etc will change the value type to cdbl but will not actually convert the variable

so if i had

dim s as string
s = 1

a = cdbl(s)

this passes the s value as double to a variable
therefore s as a variable will still be a string data type but when passed to a variable it passed it as cdbl?
as i have not dimmed a this will always be variant right or would this now always be a double?

finally i want to give a MASSIVE THANK YOU

YOU have really patient and really helpful. Its guys like you are the 1's who help us learn and with your patience, we all learn better.

you have been awesome and i really appreciate it. God bless you and may there be many more people as helpful as you out there as the world would be a better place with better people.

many thanks Rory
 
Upvote 0
CDbl returns a Double data type so, in your example, a will be a Variant that contains a Double. Because it is, and remains, a Variant your code can still later assign other data types to it.
 
Upvote 0
Thank you

i have one other slight problem

I have sent this workbook to my home address

for some reason my workbook opens and works fine but i get the circle and excel not responding from time to time and thEn sometimes i need to close the workbook. I am not sure if its this spreadsheet or excel on my computer in general that takes forever to process even though my computer is pretty quick

is there anything i can do or check to see how my excel is being run or do some analysis as i feel it may be something to do with excel processing on my computer as this has happened to other spreadsheets on my computer
 
Upvote 0
Try starting Excel in Safe Mode (hold down the Ctrl key and answer Yes to the prompt) and then open the workbook and run it for a while to see if the behaviour occurs. If not, it may be that you have an add-in causing the problem. The fact that it happens with multiple files makes me suspect that it's probably not something in the workbooks themselves.
 
Upvote 0
Hi rory the workbooks run fine in safe mode

what can i do to make if work smooth in all workbooks?

ps what is the difference safe mode? Will all macros etc work as normall in safe mode?
 
Upvote 0
As I said, it sounds like you have an add-in installed that is causing the problem.
 
Upvote 0
What do i do or run to get around this add in problems as im not sure what ive added. Can i delete repair? Because im not sure about what ive added as an add in
thank you
 
Upvote 0

Forum statistics

Threads
1,221,526
Messages
6,160,340
Members
451,637
Latest member
hvp2262

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