Please help with Form Cosmetic Programming

P

Peter Weinwurm Jr

Dear Access Expert

I have a continous form with over 30 very small columns and maybe 30 records
per screen. As a result it is hard to
know which column I am at (am I in column 22 or 23 etc..) What I would
like to do is change the color of
the label (The Label is in the Form header) which corresponds to the colum
which.has the focus. Hence it will be easy to tell
what column I am at because its label header will be red while all the
others will be black.

Detailed example of what I want...... you don't have to read this if you
understand what I want at this point.

If I am at record 5, column 15 I would like the Label for Column 15
to show up red for example while the other labels are black. Then if I
select another field in column 25 I want the column 25 Label to be red while
the others are black.


What is the most effecient way to write this code. (I know I can do it
using on got focus and lose focus of each field (column) and put this code
in
every field but that seems ridiculous to me.)

Is it possible to cycle through the labels some how using collections?
Maybe I can give the labels names like column1 or column2 and cycle through
them that way.....

Any ideas?

Thanks Peter.
 
A

Allen Browne

Hi Peter.

Simplest open might be to open the form in design view, and get Access to
set the On Got Focus and On Lost Focus properties for you.

1. Copy the functions below into a standard module (created from modules tab
of database window), and save.

2. Open the Immediate Window (Ctrl+G), and enter:
Call MakeHighLight("NameOfYourFormHere")

3. Test and save.

Public Function MakeHighlight(strFormName As String) As Boolean
Dim ctl As Control
DoCmd.OpenForm strFormName, acDesign

For Each ctl In Forms(strFormName).Controls
If ctl.ControlType = acTextBox Or ctl.ControlType = acComboBox Then
ctl.OnGotFocus = "=Highlight([" & ctl.Name & "],True)"
ctl.OnLostFocus = "=Highlight([" & ctl.Name & "],False)"
End If
Next

Set ctl = Nothing
End Function

Public Function Highlight(ctl As Control, bShow As Boolean)
ctl.BackColor = IIf(bShow, vbYellow, vbWhite)
End Function
 
P

Peter Weinwurm Jr

Wow excelletn thanks so much



Allen Browne said:
Hi Peter.

Simplest open might be to open the form in design view, and get Access to
set the On Got Focus and On Lost Focus properties for you.

1. Copy the functions below into a standard module (created from modules tab
of database window), and save.

2. Open the Immediate Window (Ctrl+G), and enter:
Call MakeHighLight("NameOfYourFormHere")

3. Test and save.

Public Function MakeHighlight(strFormName As String) As Boolean
Dim ctl As Control
DoCmd.OpenForm strFormName, acDesign

For Each ctl In Forms(strFormName).Controls
If ctl.ControlType = acTextBox Or ctl.ControlType = acComboBox Then
ctl.OnGotFocus = "=Highlight([" & ctl.Name & "],True)"
ctl.OnLostFocus = "=Highlight([" & ctl.Name & "],False)"
End If
Next

Set ctl = Nothing
End Function

Public Function Highlight(ctl As Control, bShow As Boolean)
ctl.BackColor = IIf(bShow, vbYellow, vbWhite)
End Function

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Peter Weinwurm Jr said:
Dear Access Expert

I have a continous form with over 30 very small columns and maybe 30 records
per screen. As a result it is hard to
know which column I am at (am I in column 22 or 23 etc..) What I would
like to do is change the color of
the label (The Label is in the Form header) which corresponds to the colum
which.has the focus. Hence it will be easy to tell
what column I am at because its label header will be red while all the
others will be black.

Detailed example of what I want...... you don't have to read this if you
understand what I want at this point.

If I am at record 5, column 15 I would like the Label for Column 15
to show up red for example while the other labels are black. Then if I
select another field in column 25 I want the column 25 Label to be red while
the others are black.


What is the most effecient way to write this code. (I know I can do it
using on got focus and lose focus of each field (column) and put this code
in
every field but that seems ridiculous to me.)

Is it possible to cycle through the labels some how using collections?
Maybe I can give the labels names like column1 or column2 and cycle through
them that way.....

Any ideas?

Thanks Peter.
 

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