@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.![]()
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
Yeah, this thread kind of confusing because it's resurrected, see post #18, that is the recent one.
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 ...![]()
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
Hi. What is it doing with your subform? Are you getting an error? Did you also add the Load event code in your 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, Thank you very much for the speedy reply.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. 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.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.