don't move set focus cursor to next textbox on userform if the previous textbox for the same row is empty

abdo meghari

Active Member
Joined
Aug 3, 2021
Messages
465
Office Version
  1. 2019
Hi experts
I want preventing move set focus cursor for to next textbox for the same row on userform if the previous textbox for the same row is empty
it should move to next row and start set focus cursor from first textbox in column ITEM when the whole textboxes previous are filled (if one of them not filled then should not move to next empty row should keep focus cursor for previous textbox in the same row is not all of textboxes are filled .

the textboxes numbers start from column ITEM for each row consecutive textbox66:72 and second row start textbox73:79 and so on for the rests of rows .



when filling the whole row should move to next row
1.PNG


but when try to move to next textbox for the same row as in the picture should not move cursor to textbox74 and keep cursor into textbox 73

and if there is textbox is empty but the rest of textboxes are filled with the same row then should keep set focus cursor into textbox72 without move to next row (textbox73)as this picture

3.PNG


in others words , should not move to next textbox if the pervious textbox is empty and keep the cursor in pervious textbox is empty .
thanks in advance
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
I'm afraid you're going to have to create the Exit event for each of your textboxes. I checked if it was possible to create a class for all the textboxes and in this way program only one Exit event, but custom controls do not have Exit events.

Check the following example to do it in your userform:
VBA Code:
Private Sub TextBox66_Exit(ByVal Cancel As MSForms.ReturnBoolean)
  If TextBox66.Value = "" Then Cancel = True
End Sub
Private Sub TextBox67_Exit(ByVal Cancel As MSForms.ReturnBoolean)
  If TextBox67.Value = "" Then Cancel = True
End Sub
Private Sub TextBox68_Exit(ByVal Cancel As MSForms.ReturnBoolean)
  If TextBox68.Value = "" Then Cancel = True
End Sub

'For all ...

Another option is that you only have 7 textboxes, fill them in, press a button and pass the data to the sheet or a listbox.

----- --
 
Upvote 0
Solution
'I'm afraid you're going to have to create the Exit event for each of your textboxes.I checked if it was possible to create a class for all the textboxes and in this way program only one Exit event
bad news !
I thought all of textboxes could put in one procedure instead of one by one.
but custom controls do not have Exit events.
good news :)

Temporarily this solution can be relied upon due to programming limitations in a case like this.;)

Another option is that you only have 7 textboxes, fill them in, press a button and pass the data to the sheet or a listbox.
I'm not sure what you mean . what's relating data of sheet or a listbox :unsure:just I'm talk about all of textboxes on userform .
 
Upvote 0

Forum statistics

Threads
1,214,875
Messages
6,122,039
Members
449,063
Latest member
ak94

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