Manipulating textbox class

K

Ken Warthen

Is there a way to manipulate the textbox class so that I can set the
backcolor of every textbox on a form to a value when a textbox has the focus,
and a different value when a textbox does not have the focus?

I've done this in VB.NET by creating a custom textbox class that inherits
properties of textbox, but I don't think Access 2007 supports that type of
inheritance.

Any help is greatly appreciated.
 
A

Allen Browne

It's probably possible to wrap controls in your own class, Ken, but I doubt
it would do much to enhance the stability of the app.

A quite simple get Access to assign this for you.
Save the first function in a standard module.
Open the form in design view, and run the 2nd one.
Alternatively, you could modify it to use in Form_Open if you prefer.


Public Function SetBackground(ctl As Control, IsEntering As Boolean)
If IsEntering Then
ctl.BackColor = vbYellow
Else
ctl.BackColor = vbWhite
End If
End Function

Function SetUpFormBackground(frm As Form)
Dim ctl As Control
Dim strName As String
For Each ctl In frm.Section(acDetail).Controls
Select Case ctl.ControlType
Case acTextBox, acComboBox
strName = ctl.Name
If ctl.OnEnter = vbNullString Then
ctl.OnEnter = "=SetBackground([" & strName & "],True)"
Else
Debug.Print "Skipped " & strName & " Enter"
End If
If ctl.OnExit = vbNullString Then
ctl.OnExit = "=SetBackground([" & strName & "],False)"
Else
Debug.Print "Skipped " & strName & " Exit"
End If
End Select
Next
End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top