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. |
|
|
|
Thread Tools | Display Modes |
#11
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
"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 | |
|
|
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 |