When the TextBox gets focus (GotFocus), it changes the text color. When it loses focus (LostFocus), it restores the text color. ForeColor sets the foreground color of the text.
'When the cursor moves to the TextBox, the text is set to red
Private Sub Text1_GotFocus()
Text1.ForeColor = vbRed
End Sub
'When the cursor moves out of the TextBox, the text is set to black
Private Sub Text1_LostFocus()
Text1.ForeColor = vbBlack
End Sub
The above code only needs to change Text1.ForeColor to Text1.BackColor to change the background color of TextBox.