Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do you put a red border around the current field a user is in....

Status
Not open for further replies.

Pack10

Programmer
Feb 3, 2010
495
US
On my main form when the user enters a field, I highlight the textbox to a yellow easily displaying the current text box.
Lots of applications use this sort of technique. I would really like to display a red border around the current text box the user is working in...but i can't get it to work. I did have this working at one time but I seem to have clobbered that piece of code.
When the user is in a textbox, the gotfocus event fires the following function. But as I said, the bordercolor is not taking.
I dont think that property is available in this context. Hopefully someone can show another way.



Function Highlight(Stat As String) As Integer
Dim ctrl As Control
On Error Resume Next
Set ctrl = Screen.ActiveControl
If Stat = "GotFocus" Then
ctrl.BackColor = 13434363
ctrl.BorderColor = RGB(255, 0, 0)
ElseIf Stat = "LostFocus" Then
ctrl.BackColor = 16777215
End If
End Function
 
What's the special effect setting of the control?

Remarks

A control's border color is visible only when its SpecialEffect property is set to Flat or Shadowed. If the SpecialEffect property is set to something other than Flat or Shadowed, setting the BorderColor property changes the SpecialEffect property setting to Flat.

taken from.. [URL unfurl="true"]http://msdn.microsoft.com/en-us/library/office/aa223971(v=office.11).aspx[/url]

Though if this statement was true
setting the BorderColor property changes the SpecialEffect property setting to Flat.
you would think setting the backcolor twice would work but it doesn't!

"In complete darkness we are all the same, it is only our knowledge and wisdom that separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Free Dance Music Downloads
 
The text boxes are all set to sunken for special effect.
 
Pack10 . . .

Indeed .... you need to set the textboxes to [blue]flat[/blue] if your gonna control the [purple]border color[/purple] ... [blue]1DMF[/blue] already said that! ...

[blue]Your Thoughts? . . .[/blue]

See Ya . . .

Be sure to see FAQ219-2884 Worthy Reading! [thumbsup2]
Also FAQ181-2886 Worthy Reading! [thumbsup2]
 
I know this is old thread but I needed a small challenge.
Add a rectangle to your form named box1, red 1PT border, and visible = false
two short functions
Private Function PlaceBox()
Me.Box1.Visible = True
Me.Box1.Top = Me.ActiveControl.Top - 50
Me.Box1.Left = Me.ActiveControl.Left - 50
Me.Box1.Height = Me.ActiveControl.Height + 100
Me.Box1.Width = Me.ActiveControl.Width + 100
End Function

Private Function HideBox()
Me.Box1.Visible = False
End Function

In each field you want highlighted
On got focus event type =PlaceBox()
On lost focus type =HideBox()
 
Pack10 . . .

What you suggest can be done. However its only truly realized in [blue]single form view[/blue]. In [blue]continuous form view[/blue] you'll outline entire columns ... doesn't look good.

Copy/paste the following function to the code module of the form:

Code:
[blue]Public Function ShowPos()
   Dim ctl As Control
   
   For Each ctl In Me.Controls
      If ctl.ControlType = acTextBox Then
         If ctl.Name <> ActiveControl.Name Then
            ctl.BorderWidth = 0
            ctl.BorderColor = 0
         Else
            ctl.BorderWidth = 2
            ctl.BorderColor = 128
         End If
      End If
   Next
            
End Function[/blue]

Next ... group select or highlight all the textboxes that comprise a record and enter the following in the [blue]On Got Focus[/blue] property line:

Code:
[blue] =ShowPos()[/blue]

Thats it. Open the form and navigate around ...

[blue]Your Thoughts? . . .[/blue]


See Ya . . .

Be sure to see FAQ219-2884 Worthy Reading! [thumbsup2]
Also FAQ181-2886 Worthy Reading! [thumbsup2]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top