Assignment of a VBA expression

Y

ydbc

Hi,

I am buliding a form with multiple controls on it.

I need to assign the same Event Procdure to a number of controls within hte
form.

This is what I have so far:

Private Sub Text53_AfterUpdate()
Dim ctlCurrentControl As Control
Dim Value
Set ctlCurrentControl = Screen.ActiveControl
strControlName = ctlCurrentControl.Name

Value = ctlCurrentControl
Select Case Value
Case 2.1 To 2.3
Me.Text65 = "2a"
Case 3.1 To 3.3
Me.Text65 = "3a"
End Select
End Sub

I would like to substitute the "Text53_AfterUpdate()" with whatever control
I'm on at the time.

Any suggestions would me appreciated.

Thanks
 
S

Stefan Hoffmann

hi,

I need to assign the same Event Procdure to a number of controls within hte
form.
Set ctlCurrentControl = Screen.ActiveControl
Imho while this may be true, I would not rely on it.
I would like to substitute the "Text53_AfterUpdate()" with whatever control
I'm on at the time.
Use a simpler approach:

Private Function AfterUpdateByName(AControlName As String _
) As Boolean

Dim ctlCurrentControl As Access.Control

Set ctlCurrentControl = Controls.Item(AControlName)
MsgBox ctlCurrentControl.Value

AfterUpdateByName = True

End Function

Private Function AfterUpdateByControl(AControl As Access.Control _
) As Boolean

MsgBox AControl.Value

AfterUpdateByControl = True

End Function


And bind it to the event in the property editor:

After Update: =AfterUpdateByName("myTextControl")

or

After Update: =AfterUpdateByControl([myTextControl])

mfG
--> stefan <--
 
D

Daryl S

Ydbc -

Your best bet would be to put this code in a public subroutine, accepting
Value as a parameter, and then call it from all the control events you want.
That way if you need to change the code, you will only need to change it one
place instead of every place.

Another option is if these are all AfterUpdate events on bound controls, you
can do the same with the form AfterUpdate event.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top