Originally Posted by
grizzli00
The script says [Choice] = 1
I want to assign the same script to ALL text box (except [Choice] )
Hi!
If you want to reset the value of Choice to 1 by Enter of the rest textboxes, follow those steps:
1. In code module of your form, create a public function as folows:
Code:
Function ResetChoise()
Me!Choice = 1
End Function
2. In design view, select all desired texboxes of your form and type the expression =ResetChoise() in the property OnEnter of selected controls as seems in the picture below:
But, if you want to pass the corresponding property of the current control (.Value, Tag, .Name or whatever) to the Choice, you have to follow an other path.
1. Paste the code below in a new Class module named clsTextbox:
Code:
Option Compare Database
Option Explicit
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'Code for a Class module.
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Public WithEvents Target As TextBox
'
Private Sub MyTextBox_Enter()
Target.Parent!Choice = Target.Tag
End Sub
2. Paste the code below in the code module of your form:
Code:
Option Compare Database
Option Explicit
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'Code for a Form module.
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Private colMyTextboxes As Collection
'
Private Sub Form_Load()
Dim ct As clsTextbox
Dim c As Control
Dim i As Integer
'Create a local collection.
Set colMyTextboxes = New Collection
For Each c In Me.Controls
If c.ControlType = acTextBox Then
'Skip the Choice control.
If c.Name <> "Choice" Then
i = i + 1
'Set the Tag of textbox.
c.Tag = i
'Enable the Enter event of textbox.
c.OnEnter = "[Event procedure]"
'Create an instance of clsTextbox.
Set ct = New clsTextbox
'Point this instance to this textbox.
Set ct.Target = c
'Keep this instance in collection.
colMyTextboxes.Add ct, c.Name
End If
End If
Next c
End Sub
Private Sub Form_Unload(Cancel As Integer)
'Release the collection with all instances.
Set colMyTextboxes = Nothing
End Sub
In any case, open your form and check the results and let us know if works as you expected.
I hope you are still with us,
John