Detecting a press of tab button or a change of textbox with VBA

Fire_Chief

Well-known Member
Joined
Jun 21, 2003
Messages
690
Office Version
  1. 365
Platform
  1. Windows
I have a user form ("Participants_Info" is the name of the user form). When this form is brought up I want to detect when the user either presses the Tab button
or uses the mouse to change the cursor to a different box. There are 2 comboboxes and 3 textboxes. The second name is if there are two participants.
I want to be sure there is something in the box when they move to the next one. I know there is code to do this but I can't figure it out.
I think I have tried all of the choices available but can't get it to detect both.

I have posted before with no answers.
Capture.Png

Thank You
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Hi,
one idea, you could enable the controls in sequence so that users can only tab once data has been entered in each required control

something like following maybe

VBA Code:
Private Sub ComboBox1_Change()
    EnableControls
End Sub

Private Sub ComboBox2_Change()
    EnableControls
End Sub

Private Sub TextBox1_Change()
    EnableControls
End Sub

Private Sub TextBox2_Change()
    EnableControls
End Sub


Sub EnableControls()
    Me.TextBox1.Enabled = Me.ComboBox1.ListIndex <> -1
    Me.ComboBox2.Enabled = IsEmail(Me.TextBox1.Text)
    Me.TextBox2.Enabled = Me.ComboBox2.ListIndex <> -1 And Me.TextBox1.Enabled
    Me.TextBox3.Enabled = Me.ComboBox2.Enabled
End Sub

Private Function IsEmail(ByVal Text As String) As Boolean
IsEmail = InStr(1, Text, ".") <> 0 And InStr(1, Text, "@") <> 0
End Function

Private Sub UserForm_Initialize()
    EnableControls
End Sub

I have included a very simple function to check text entered in textbox looks like an email address

This is just an idea, you will need to adjust code as required to meet specific project need

Dave
 
Upvote 0
Solution
Hey Dave
I played with your code some and I think I can get it to work.

Can't get at it for a couple days but will let you know.

Thanks again
 
Upvote 0

Forum statistics

Threads
1,214,942
Messages
6,122,366
Members
449,080
Latest member
Armadillos

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