On entery Field changes colour (1 Viewer)

stu_gnu

Registered User.
Local time
Today, 09:21
Joined
Jun 27, 2001
Messages
10
Hi

I want to enable the fields in my form so that on entery they change colour is this possible to do and if so will I have to enable each field individually or can I do them all in a group.
 

Mike Smith

Registered User.
Local time
Today, 09:21
Joined
Sep 22, 2000
Messages
20
Stu,
I had the same problem & have a great solution. Wish I could take credit for it but I can't. I got my help from Gyula Gulyas over at allexperts.com.

1. Insert this code into a new module
2. Replace "Table1" with your form name
3. Run the FormFiller (by placing your cursor next to the "Sub Formfiller" line and hitting F5)

This will place the function calls into the GotFocus and LostFocus events of each control that is a textbox type.

---------- code starts here -----------

Public Function TextGotFocus(strFrmName As String, strCtrlName As String)
Dim dbs As Database
Dim frm As Form
Dim ctrl As Control

Set dbs = CurrentDb
Set frm = Forms(strFrmName)
frm.Controls(strCtrlName).BackColor = 10079487
End Function
Public Function TextLostFocus(strFrmName As String, strCtrlName As String)
Dim dbs As Database
Dim frm As Form
Dim ctrl As Control

Set dbs = CurrentDb
Set frm = Forms(strFrmName)
frm.Controls(strCtrlName).BackColor = vbWhite
End Function

Sub Formfiller()
Dim dbs As Database
Dim frm As Form
Dim ctrl As Control

Set dbs = CurrentDb()
DoCmd.OpenForm "Table1", acDesign
Set frm = Forms("Table1")

For Each ctrl In frm.Controls
If ctrl.ControlType = acTextBox Then
ctrl.OnGotFocus = "=TextGotFocus(""" & frm.Name & """,""" & ctrl.Name & """)"
ctrl.OnLostFocus = "=TextLostFocus(""" & frm.Name & """,""" & ctrl.Name & """)"
End If
Next ctrl

DoCmd.Close acForm, "Table1", acSaveYes
End Sub


----------- end of code -------------

Hope it helps!
Mike
 

russi

Registered User.
Local time
Today, 09:21
Joined
Jul 18, 2000
Messages
385
This is primitive, perhaps, but should help.

Once I have my form, I use hold the SHift Key and select all the data entry fields that I want this option for.
Then I simply go to the Back Style Property of a selected field and change it to Transparent.
All the selected fields get this property
AND AUTOMATICALLY whenever it gets the focus, the original color for the field comes through! Then, when focus is lost, you STILL CAN SEE the data entered, but it loses the back color.

Hope this helps you.
 

Users who are viewing this thread

Top Bottom