Moving the cursor to another textbox after Enter Event - VBA

DECOVIOTI

New Member
Joined
Dec 11, 2020
Messages
22
Office Version
  1. 2019
Platform
  1. Windows
Could you please help me?

With the code below, I can "Setfocus" and change the "Backcolor" of "Me.txtFT".

But, when I am trying to move the cursor to "Me.txtFT" after an "Enter" event on "txtPT", the cursor is not moving, it keeps on the "txtPT".

I am using the code below.

VBA Code:
Private Sub txtPT_Enter()
    If Trim(Me.txtPT.Value & vbNullString) = 0 Then
        MsgBox """PT field"" must contain a value before continue. Please try again": _
        Me.txtFT.SetFocus: _
        Me.txtFT.BackColor = &H80FFFF: _
        Exit Sub
    End If
End Sub

Could you pls help me?
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
you are trying to trap an error in the text entry. shouldnt this be done on txtPT_Exit ?
 
Upvote 0
Hello @diddi
I am quite new in VBA and I am trying to learn as much as possible.
My idea is if the user try to select the "me.txtPT" before insert an amount in "me.txtFT", the user get a message and the cursor goes to the "me.txtFT".

I just realize now the user message should be "MsgBox """FT field"" must contain a value before continue. Please try again":"
 
Upvote 0
see if this works for you. in place if the sub you posted

VBA Code:
Private Sub txtFT_Exit()
    If Val(Trim(txtFT.Value)) = 0 Then
        MsgBox "This field must contain a value before continue. Please try again"
        Me.txtFT.SetFocus
        Me.txtFT.BackColor = &H80FFFF
    End If
End Sub
 
Upvote 0
Thanks for the suggestion..

But the action needs to be in the "me.txtPT" text box and in case of the user tries to access the "Me.txtPT" and there is no value in "Me.txtFT", then the cursor needs to move to "Me.txtFT"
 
Upvote 0

Forum statistics

Threads
1,214,981
Messages
6,122,565
Members
449,089
Latest member
Motoracer88

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