A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Show field which has focus in different color



 
 
Thread Tools Display Modes
  #11  
Old September 11th, 2004, 05:08 PM
Allen Browne
external usenet poster
 
Posts: n/a
Default

No. Just save the code in a module, and enter the line into the immediate
window naming each form you want to behave like this.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Anne" wrote in message
...
Got it, but I need to use it for several forms. Do I create a new module
for
every form?
Anne

"Allen Browne" wrote in message
...
1. Select the module tab of the Database window, and click New.
Access opens a new module.

2. Paste in the code.

3. Open the Immediate window: Ctrl+G

4. Enter:
? SetupHightlight("Form1")
substituting your actual form name for Form1.

The code will run, and set the OnLostFocus and OnGotFocus properties of
controls on the form. These events will call the other function, which
actually does the highlighting and dehighlighting.


"Anne" wrote in message
...
I like your solution, but I am not sure how to use it.
I put your code into a module, but I do not know what to put on the
form
to
activate it.
Anne

"Allen Browne" wrote in message
...
Yes, you need to put this in the events of each control, but you can
do
that
programmatically.

The following example opens the form in design view, and sets the
OnGotFocus
and OnLostFocus properties of all the text boxes and combo boxes:

Function SetupHightlight(strForm As String)
Dim ctl As Control
Dim strName As String

DoCmd.OpenForm strForm, acDesign
For Each ctl In Forms(strForm).Controls
Select Case ctl.ControlType
Case acTextBox, acComboBox
strName = ctl.Name
ctl.OnGotFocus = "=HighLight([" & strName & "], True)"
ctl.OnLostFocus = "=HighLight([" & strName & "], False)"
End Select
Next
Set ctl = Nothing
End Function
Public Function Highlight(ctl As Control, bHighlighted As Boolean)
If bHighlighted Then
ctl.BackColor = vbYellow
Else
ctl.BackColor = vbWhite
End If
End Function



  #12  
Old September 11th, 2004, 05:09 PM
Allen Browne
external usenet poster
 
Posts: n/a
Default

You pasted the code into the module?
Then entered the line starting with the question mark into the Immediate
Window? And pressed Enter?

Did you receive an error?
Did you save the form, and test it?

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Anne" wrote in message
...
I had sent the other reponse before I even tried it. But cannot get this to
work.
I pasted your code into new new module.
I pasted:
? SetupHightlight("FrmContractor") - FrmContractor is one of my forms.
with the question mark in front of it. But it does nothing when click
through the form.
Anne



"Allen Browne" wrote in message
...
1. Select the module tab of the Database window, and click New.
Access opens a new module.

2. Paste in the code.

3. Open the Immediate window: Ctrl+G

4. Enter:
? SetupHightlight("Form1")
substituting your actual form name for Form1.

The code will run, and set the OnLostFocus and OnGotFocus properties of
controls on the form. These events will call the other function, which
actually does the highlighting and dehighlighting.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Anne" wrote in message
...
I like your solution, but I am not sure how to use it.
I put your code into a module, but I do not know what to put on the
form
to
activate it.
Anne

"Allen Browne" wrote in message
...
Yes, you need to put this in the events of each control, but you can
do
that
programmatically.

The following example opens the form in design view, and sets the
OnGotFocus
and OnLostFocus properties of all the text boxes and combo boxes:

Function SetupHightlight(strForm As String)
Dim ctl As Control
Dim strName As String

DoCmd.OpenForm strForm, acDesign
For Each ctl In Forms(strForm).Controls
Select Case ctl.ControlType
Case acTextBox, acComboBox
strName = ctl.Name
ctl.OnGotFocus = "=HighLight([" & strName & "], True)"
ctl.OnLostFocus = "=HighLight([" & strName & "], False)"
End Select
Next
Set ctl = Nothing
End Function
Public Function Highlight(ctl As Control, bHighlighted As Boolean)
If bHighlighted Then
ctl.BackColor = vbYellow
Else
ctl.BackColor = vbWhite
End If
End Function



  #13  
Old September 11th, 2004, 05:26 PM
Anne
external usenet poster
 
Posts: n/a
Default

I did not hit enter before after entering into the immediate window:
Now I got compile error, ambiguous name detected: SetUpHightlight
I copied and pasted my codes, so you can see what I have:

Function SetupHightlight(strForm As String)
Dim ctl As Control
Dim strName As String

DoCmd.OpenForm strForm, acDesign
For Each ctl In Forms(strForm).Controls
Select Case ctl.ControlType
Case acTextBox, acComboBox
strName = ctl.Name
ctl.OnGotFocus = "=HighLight([" & strName & "], True)"
ctl.OnLostFocus = "=HighLight([" & strName & "], False)"
End Select
Next
Set ctl = Nothing
End Function
Public Function Highlight(ctl As Control, bHighlighted As Boolean)
If bHighlighted Then
ctl.BackColor = vbYellow
Else
ctl.BackColor = vbWhite
End If
End Function

Immediate window:
? SetupHightlight("FrmContractor")


"Allen Browne" wrote in message
...
You pasted the code into the module?
Then entered the line starting with the question mark into the Immediate
Window? And pressed Enter?

Did you receive an error?
Did you save the form, and test it?

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Anne" wrote in message
...
I had sent the other reponse before I even tried it. But cannot get this

to
work.
I pasted your code into new new module.
I pasted:
? SetupHightlight("FrmContractor") - FrmContractor is one of my forms.
with the question mark in front of it. But it does nothing when click
through the form.
Anne



"Allen Browne" wrote in message
...
1. Select the module tab of the Database window, and click New.
Access opens a new module.

2. Paste in the code.

3. Open the Immediate window: Ctrl+G

4. Enter:
? SetupHightlight("Form1")
substituting your actual form name for Form1.

The code will run, and set the OnLostFocus and OnGotFocus properties of
controls on the form. These events will call the other function, which
actually does the highlighting and dehighlighting.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Anne" wrote in message
...
I like your solution, but I am not sure how to use it.
I put your code into a module, but I do not know what to put on the
form
to
activate it.
Anne

"Allen Browne" wrote in message
...
Yes, you need to put this in the events of each control, but you can
do
that
programmatically.

The following example opens the form in design view, and sets the
OnGotFocus
and OnLostFocus properties of all the text boxes and combo boxes:

Function SetupHightlight(strForm As String)
Dim ctl As Control
Dim strName As String

DoCmd.OpenForm strForm, acDesign
For Each ctl In Forms(strForm).Controls
Select Case ctl.ControlType
Case acTextBox, acComboBox
strName = ctl.Name
ctl.OnGotFocus = "=HighLight([" & strName & "], True)"
ctl.OnLostFocus = "=HighLight([" & strName & "], False)"
End Select
Next
Set ctl = Nothing
End Function
Public Function Highlight(ctl As Control, bHighlighted As Boolean)
If bHighlighted Then
ctl.BackColor = vbYellow
Else
ctl.BackColor = vbWhite
End If
End Function





  #14  
Old September 11th, 2004, 05:58 PM
Allen Browne
external usenet poster
 
Posts: n/a
Default

The "ambiguious name" error means that you already have function or sub with
that name, or you pasted the function twice, or you tried to use the same
name for the module itself.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Anne" wrote in message
...
I did not hit enter before after entering into the immediate window:
Now I got compile error, ambiguous name detected: SetUpHightlight
I copied and pasted my codes, so you can see what I have:

Function SetupHightlight(strForm As String)
Dim ctl As Control
Dim strName As String

DoCmd.OpenForm strForm, acDesign
For Each ctl In Forms(strForm).Controls
Select Case ctl.ControlType
Case acTextBox, acComboBox
strName = ctl.Name
ctl.OnGotFocus = "=HighLight([" & strName & "], True)"
ctl.OnLostFocus = "=HighLight([" & strName & "], False)"
End Select
Next
Set ctl = Nothing
End Function
Public Function Highlight(ctl As Control, bHighlighted As Boolean)
If bHighlighted Then
ctl.BackColor = vbYellow
Else
ctl.BackColor = vbWhite
End If
End Function

Immediate window:
? SetupHightlight("FrmContractor")


"Allen Browne" wrote in message
...
You pasted the code into the module?
Then entered the line starting with the question mark into the Immediate
Window? And pressed Enter?

Did you receive an error?
Did you save the form, and test it?

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Anne" wrote in message
...
I had sent the other reponse before I even tried it. But cannot get this

to
work.
I pasted your code into new new module.
I pasted:
? SetupHightlight("FrmContractor") - FrmContractor is one of my forms.
with the question mark in front of it. But it does nothing when click
through the form.
Anne



"Allen Browne" wrote in message
...
1. Select the module tab of the Database window, and click New.
Access opens a new module.

2. Paste in the code.

3. Open the Immediate window: Ctrl+G

4. Enter:
? SetupHightlight("Form1")
substituting your actual form name for Form1.

The code will run, and set the OnLostFocus and OnGotFocus properties
of
controls on the form. These events will call the other function, which
actually does the highlighting and dehighlighting.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Anne" wrote in message
...
I like your solution, but I am not sure how to use it.
I put your code into a module, but I do not know what to put on the
form
to
activate it.
Anne

"Allen Browne" wrote in message
...
Yes, you need to put this in the events of each control, but you
can
do
that
programmatically.

The following example opens the form in design view, and sets the
OnGotFocus
and OnLostFocus properties of all the text boxes and combo boxes:

Function SetupHightlight(strForm As String)
Dim ctl As Control
Dim strName As String

DoCmd.OpenForm strForm, acDesign
For Each ctl In Forms(strForm).Controls
Select Case ctl.ControlType
Case acTextBox, acComboBox
strName = ctl.Name
ctl.OnGotFocus = "=HighLight([" & strName & "], True)"
ctl.OnLostFocus = "=HighLight([" & strName & "],
False)"
End Select
Next
Set ctl = Nothing
End Function
Public Function Highlight(ctl As Control, bHighlighted As Boolean)
If bHighlighted Then
ctl.BackColor = vbYellow
Else
ctl.BackColor = vbWhite
End If
End Function







  #15  
Old September 11th, 2004, 06:10 PM
Anne
external usenet poster
 
Posts: n/a
Default

Yeah, after it did not work the first time, I tried a second module. I
deleted the second module and it is now working. My mistake orginally was
that I did not hit enter in the immediate window.
How can I use this for other forms as well?
Anne

"Allen Browne" wrote in message
...
The "ambiguious name" error means that you already have function or sub

with
that name, or you pasted the function twice, or you tried to use the same
name for the module itself.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Anne" wrote in message
...
I did not hit enter before after entering into the immediate window:
Now I got compile error, ambiguous name detected: SetUpHightlight
I copied and pasted my codes, so you can see what I have:

Function SetupHightlight(strForm As String)
Dim ctl As Control
Dim strName As String

DoCmd.OpenForm strForm, acDesign
For Each ctl In Forms(strForm).Controls
Select Case ctl.ControlType
Case acTextBox, acComboBox
strName = ctl.Name
ctl.OnGotFocus = "=HighLight([" & strName & "], True)"
ctl.OnLostFocus = "=HighLight([" & strName & "], False)"
End Select
Next
Set ctl = Nothing
End Function
Public Function Highlight(ctl As Control, bHighlighted As Boolean)
If bHighlighted Then
ctl.BackColor = vbYellow
Else
ctl.BackColor = vbWhite
End If
End Function

Immediate window:
? SetupHightlight("FrmContractor")


"Allen Browne" wrote in message
...
You pasted the code into the module?
Then entered the line starting with the question mark into the

Immediate
Window? And pressed Enter?

Did you receive an error?
Did you save the form, and test it?

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Anne" wrote in message
...
I had sent the other reponse before I even tried it. But cannot get

this
to
work.
I pasted your code into new new module.
I pasted:
? SetupHightlight("FrmContractor") - FrmContractor is one of my

forms.
with the question mark in front of it. But it does nothing when click
through the form.
Anne



"Allen Browne" wrote in message
...
1. Select the module tab of the Database window, and click New.
Access opens a new module.

2. Paste in the code.

3. Open the Immediate window: Ctrl+G

4. Enter:
? SetupHightlight("Form1")
substituting your actual form name for Form1.

The code will run, and set the OnLostFocus and OnGotFocus properties
of
controls on the form. These events will call the other function,

which
actually does the highlighting and dehighlighting.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Anne" wrote in message
...
I like your solution, but I am not sure how to use it.
I put your code into a module, but I do not know what to put on

the
form
to
activate it.
Anne

"Allen Browne" wrote in message
...
Yes, you need to put this in the events of each control, but you
can
do
that
programmatically.

The following example opens the form in design view, and sets the
OnGotFocus
and OnLostFocus properties of all the text boxes and combo boxes:

Function SetupHightlight(strForm As String)
Dim ctl As Control
Dim strName As String

DoCmd.OpenForm strForm, acDesign
For Each ctl In Forms(strForm).Controls
Select Case ctl.ControlType
Case acTextBox, acComboBox
strName = ctl.Name
ctl.OnGotFocus = "=HighLight([" & strName & "],

True)"
ctl.OnLostFocus = "=HighLight([" & strName & "],
False)"
End Select
Next
Set ctl = Nothing
End Function
Public Function Highlight(ctl As Control, bHighlighted As

Boolean)
If bHighlighted Then
ctl.BackColor = vbYellow
Else
ctl.BackColor = vbWhite
End If
End Function








  #16  
Old September 12th, 2004, 07:11 AM
Allen Browne
external usenet poster
 
Posts: n/a
Default

"Anne" wrote in message
...
How can I use this for other forms as well?


Same way in the immediate window: just use the name of another form.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.


 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
No BG Color or Text Color in OE6 Bernard R Buchta Outlook Express 3 August 29th, 2004 03:22 AM
NUMBERING the pages Bob New Users 7 June 14th, 2004 12:20 AM
COMPARE THE TWO TABLES Stefanie General Discussion 0 June 4th, 2004 04:36 PM
Supress blank lines in DOCPROPERTY field Mary Formatting Long Documents 10 May 25th, 2004 07:27 PM
Make a field lookup dependent on the value in another field of a record? Susan A Database Design 8 May 22nd, 2004 09:10 PM


All times are GMT +1. The time now is 05:08 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.