Form coding for controls

CharlesWilliams

Registered User.
Local time
Today, 16:20
Joined
Dec 7, 2004
Messages
70
Hello Access Experts,

I need help with a little coding please.

I have a form (see attached) and every time someone goes to a different field I would like to change the border to red and when they leave that field to change the border back to the default color. I know I can put the code in for each fields got focus and lost focus section but would rather be able to put the code in once and for it to work for all the fields.

Any help you could provide would be greatly appreciated.

Charles Williams
 

Attachments

  • Form Snapshot.jpg
    Form Snapshot.jpg
    94.5 KB · Views: 143
Search around for "Conditional Formatting." You can make that happen without writing code.
 
You can use Conditional Formatting if you can settle for setting the font or backcolor. To change the border, you're going to have to code it. You can probably use a function and ActiveControl, but I think you still have to fire it off from the focus events. I can't think of a form level event that would fire as you change controls.
 
Sorry Mark, your post wasn't there when I started typing. Can you change the border with CF in a later version? You couldn't through 2007.
 
Sorry Mark, your post wasn't there when I started typing. Can you change the border with CF in a later version? You couldn't through 2007.
Can't in 2010 Paul.

If you want to use Conditional Formatting you can:
1. Create a textbox and set its Enabled property to No and Locked property to Yes
2. Enlarge the textbox so that it's big enough to just cover the original textbox. Enough to make it look like a border
3. Apply Conditional Formatting on the Back Color of this textbox
4. Send the textbox to the back

But I'll go with doing it code like pbaldy mentioned since it's a Single Form.
 
My mistake. You cannot set border properties using Conditional Formatting.

I think conditional formatting is still a good choice though, for highlighting the control that has the focus.
 
I think conditional formatting is still a good choice though, for highlighting the control that has the focus.

I agree; I'd set the backcolor, and you can probably highlight all the controls and set the CF for all of them at once.
 
Sorry guys I should have said from the beginning that I am using Access 2007.

This is the test I did make sure the code works:

Private Sub RecordID_GotFocus()
Call SetBorderColor
End Sub

Private Sub RecordID_LostFocus()
Call ResetBorderColor
End Sub

With the modules:

Function SetBorderColor()
On Error Resume Next
Screen.ActiveControl.BorderColor = 255
End Function

And

Function ResetBorderColor()
On Error Resume Next
Screen.ActiveControl.BorderColor = 80000027
End Function

This is the idea I had:

Private Sub Form_Current()
dim frm as form, dim fld as field

for each fld in frm

If gotfocus them
Call SetBorderColor

All other fields
Call resetBorderColor

End Sub

I know it cannot be that simple (It never is)! any help with this would be greatly appreciated.

- Charles Williams
 
The current event is going to fire when you change records, not when you move from control to control.
 
Thank You spikepl I believe that is just what I am looking for!

I'm going to try and play with it and let you know.

- Charles Williams
 

Users who are viewing this thread

Back
Top Bottom