LostFocus VBA Form Events not firing and SetFocus method also not working

RainerGaier

New Member
Joined
Aug 10, 2023
Messages
4
Office Version
  1. 365
Platform
  1. Windows
I would appreciate it if anybody is able to shed some light as to why these two issues occur ... I also recognize that they may not be related in any way but both are occurring

I have tried a very simple form with two Text fields (TextBox1 & TextBox2) and added the code below ...

Private Sub TextBox1_LostFocus()
MsgBox "Moving off TextBox1"
End Sub

Private Sub TextBox1_AfterUpdate()
MsgBox "Updated TextBox1"
TextBox1.SetFocus
End Sub


The first event never fires when I switch between the two fields.
I get the second message after entering data in TextBox1. So the AfterUpdate event fires.
However, the SetFocus doesn't position the cursor back at the first field.

Thanks in advance.
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
A textbox on a userform doesn't have a LostFocus event.

The second one actually does set the focus but that happens prior to exiting the control based on user actions. If you want to prevent the user exiting, you would use the Exit or BeforeUpdate events, which both provide a Cancel argument.
 
Upvote 0

Forum statistics

Threads
1,215,088
Messages
6,123,056
Members
449,091
Latest member
ikke

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