Change border color of textboxes when they have focus

Wow that's terrible news, way back he helped me on a database... He knew his Access for sure! isladogs, thank you!
 
Hmm, in thinking about this you might be able to hack this. You might be able to adapt the below by putting it behind the Label...
https://regina-whipp.com/blog/?p=1029 (You will need to adjust the line accordingly.)

I know it works on continuous forms so at least that part is resolved.
 
@isladogs

Pretty cool samples! (I never use split forms either!)
 
Thanks Gina
Both split forms and navigation forms are on my list of items that I NEVER use along with attachment fields, MVFs and table level lookups

However I do use my hat method for highlighting current record in lots of continued jobs forms. Many years ago I also made a couple of reports that use your approach to show horizontal blocks whose length depends on the field value. TBH I’d completely forgotten about that method.

I must have another look at all the goodies on your website
 
@isladogs

Yep, ALL things on my *Do Not Use* list!

I was just peeking at your site to see what goodies you have! Great minds think alike. :D
 
@isladogs

Yep, ALL things on my *Do Not Use* list!

I was just peeking at your site to see what goodies you have! Great minds think alike. :D

The examples & samples part of my site is still work in progress.
I'm currently working on a number of articles then will add loads of links to other sites - all the usual suspects of course ... then there are a few more examples to add.

I'm currently looking at Access 95 files in relation to Access (non) security & trying to remember how ULS is meant to work. Fun!
 
@shadow9449

While that one is great it does not work with continuous forms which was needed in this case.
 
@Gina:

While I did notice people discussing continuous forms, I didn't see that (I still don't) in the original post.

Either way, maybe someone searching for the topic will find it helpful :)
 
The examples & samples part of my site is still work in progress.
I'm currently working on a number of articles then will add loads of links to other sites - all the usual suspects of course ... then there are a few more examples to add.

I'm currently looking at Access 95 files in relation to Access (non) security & trying to remember how ULS is meant to work. Fun!

Already bookmarked your site!
 
@shadow9449

Yeah, this thread kind of confusing because it's resurrected, see post #18, that is the recent one.

And yes, it is bound to help someone else!
 
Shadow
Oxicottin came in and sort of hijacked this thread leading it in a different direction
A bit like someone else did in a current thread about Windows/Office upgrade woes....! Naming no names of course ... ;)
 
Shadow
Oxicottin came in and sort of hijacked this thread leading it in a different direction
A bit like someone else did in a current thread about Windows/Office upgrade woes....! Naming no names of course ... ;)


Amazing...what kind of @#%*& would do that...??

lol
 
Okay first off you would need to use
For Each ctl in frm.CONTROLS

or did you just accidentally omit it in the code you posted here?

Second, your reference to set them is not right.

What I would do is create a Function like this in a standard module:

Code:
Function SetFocusCtl(strFrm As String, strCtlNameWithFocus As String, blnFocus As Boolean)
    Dim strActiveColor As String: strActiveColor = RGB(255, 0, 0)
    Dim strNonActiveColor As String: strNonActiveColor = RGB(0, 0, 0)
    Const intActiveWidth As Integer = 3
    Const intNonActiveWidth As Integer = 1
    Dim ctl As Control
    Dim frm As Form

    Set frm = Forms(strFrm)

    For Each ctl In frm.Controls
        Select Case ctl.ControlType
        Case acTextBox, acComboBox, acListBox, acOptionGroup
            If ctl.Name = strCtlNameWithFocus Then
                ctl.BorderColor = strActiveColor
                ctl.BorderWidth = intActiveWidth
            Else
                ctl.BorderColor = strNonActiveColor
                ctl.BorderWidth = intNonActiveWidth
            End If
        End Select
    Next ctl

End Function

And then in the form's On Load event Or Open event:

Code:
Private Sub Form_Load()
    Dim ctl As Control
    Dim strGot As String
    Dim strLost As String

  
    For Each ctl In Me.Controls
        Select Case ctl.ControlType
        Case acTextBox, acComboBox, acListBox, acOptionGroup
            With ctl
            strGot = "=SetFocusCtl([Form].[Name],[" & ctl.Name & "].[Name], True)"
            strLost = "=SetFocusCtl([Form].[Name],[" & ctl.Name & "].[Name], False)"
                .OnGotFocus = strGot
                .OnLostFocus = strLost
            End With
        End Select
    Next
End Sub


Thank you very much for this. This code works amazingly on my main form but not on my subform. Can you please show code to include subforms? or advise how to have this 'change border color function on my subform.
 
Thank you very much for this. This code works amazingly on my main form but not on my subform. Can you please show code to include subforms? or advise how to have this 'change border color function on my subform.
Hi. What is it doing with your subform? Are you getting an error? Did you also add the Load event code in your subform?
 
Hi. What is it doing with your subform? Are you getting an error? Did you also add the Load event code in your subform?
Hi, Thank you very much for the speedy reply.
I have tried various methods/adaptations of this code to include my subform but been unsuccessful each time. I Think the issue is, I have not referenced my subform on my main form.
So the border colour changes in my main form as expected but when I tab to my subform I get the error “2450 - Cannot find referenced subform” OR I can tab to the subform but the focus (border colour change) remains on the last control in my main form.
 
Hi, Thank you very much for the speedy reply.
I have tried various methods/adaptations of this code to include my subform but been unsuccessful each time. I Think the issue is, I have not referenced my subform on my main form.
So the border colour changes in my main form as expected but when I tab to my subform I get the error “2450 - Cannot find referenced subform” OR I can tab to the subform but the focus (border colour change) remains on the last control in my main form.
Hi. When you get the error and hit the Debug button, which line gets highlighted?
 
Hi, Thank you very much for the speedy reply.
I have tried various methods/adaptations of this code to include my subform but been unsuccessful each time. I Think the issue is, I have not referenced my subform on my main form.
So the border colour changes in my main form as expected but when I tab to my subform I get the error “2450 - Cannot find referenced subform” OR I can tab to the subform but the focus (border colour change) remains on the last control in my main form.
Hi. I got it to work, but I didn't like the result (nor the method). When I go to a textbox on the subform, it gets the red border, but when I tab out of the textbox to go to a button, the textbox is still highlighted in red. Regarding the method, it loops through all the form controls every time the event fires. It can be modified to know right away which control has the focus and just go there directly without checking all the controls first.
 

Users who are viewing this thread

Back
Top Bottom