Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing a controls property 2

Status
Not open for further replies.

AccessGuruCarl

Programmer
Jul 3, 2004
471
US
I'd like to create a module to change the backcolor, forecolor for textboxes on Got/Lost Focus.

Please help with the following Function.
I've alway's stayed away from modules for this reason.
I believe I'm missing the Form Name to make it work.

Here's what I got started,
Code:
Public Function TextGotFocus(strTextBoxName As String)
On Error Resume Next
   With Me.Controls(strTextBoxName)
        .BackColor = 11796479   'custom Light Yellow
        .SelStart = 0
    End With
End Function
Thanks...


AccessGuruCarl
Programmers helping programmers
you can't find a better site.
 
I would pass the argument by reference so it wouldn't matter which form called the function:
Code:
Public Function TextGotFocus(ByRef tb As TextBox)
On Error Resume Next
  With tb
    .BackColor = 11796479   'custom Light Yellow
    .SelStart = 0
  End With
End Function
The form would call it like this:
Code:
Private Sub Text1_GotFocus()
  Call TextGotFocus(Me!Text1)
End Sub

VBSlammer
redinvader3walking.gif

"You just have to know which screws to turn." - Professor Bob
 
You may consider passing the control object instead of the name as parameter:
Code:
Public Function TextGotFocus(objTextBox As Control)
    With objTextBox
        .BackColor = 11796479   'custom Light Yellow
        .SelStart = 0
    End With
End Function

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thanks,

Both methods worked.

Star for each :)

AccessGuruCarl
Programmers helping programmers
you can't find a better site.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top