SetValue in a Macro - 2000

  • Thread starter Thread starter DaveT
  • Start date Start date
D

DaveT

Guest
I have a form with 10 Controls (Fields) for entering a new record into a table. I have written a small macro with the SetValue command so that when a field gets the focus, the border changes from it’s setting of transparent to a solid line. It’s obviously only an aesthetic change however it does help to remove clutter and give a focus on the particular control. My problem is that due to my lack (This is my first foray into macros) of understanding the multitude of options (controls) I will have to write a separate macro for each field to turn the border on/off. The current macro reads like “SetValue [Forms]![New Data]![ID].[BorderStyle] 1”
Is there a way of replacing the field control part of the above statement, [ID], with something that refers to the active control or do I have to write 10 separate macros for each field, plus of course 10 separate macros to SetValue back to the original setting?
I would appreciate any advice.
 
Hello Dave

This code works in Access 97 and should in 2000. I have set up four text box controls on a form. The text boxes are named just how Access puts them there (not too meaningful but I trust you'll use better names). In the Got Focus event of each text box the sub BorderHandler is called. This sub changes the border color of the active control (border styles must be set to solid) to red. The control name is stored as a string in the variable "oldcont" stored in the declarations section of the form. If "oldcont" is anything but a zero length string it will contain the name of the previous control who's border color we set back to black.

Option Compare Database
Option Explicit
Dim oldcont As String

Public Sub BorderHandler()

On Error GoTo BorderHandler_Err


'Set the active control border color
Me.ActiveControl.BorderColor = 255

'Find if oldcont contains the name
'of the previous control
If oldcont <> "" Then
'Set previous control border to black
Me(oldcont).BorderColor = 0
End If

'Store new control name in variable
'because it will now be the previous control
oldcont = Me.ActiveControl.Name
Exit Sub

BorderHandler_Err:
MsgBox Error$, 16, "Error"
Exit Sub
End Sub

Private Sub Text1_GotFocus()

BorderHandler

End Sub

Private Sub Text3_GotFocus()

BorderHandler

End Sub

Private Sub Text5_GotFocus()

BorderHandler

End Sub

Private Sub Text7_GotFocus()

BorderHandler

End Sub

Have fun
Robin
 
Robin, Thanks very much for your reply. It looks like it might do the trick for me however I was using a macro (initially) as I have yet to delve into “Code” . That said, I had every intention of doing so and now seems as good a time as any. Thanks again Robin.
 

Users who are viewing this thread

Back
Top Bottom