PC Review


Reply
Thread Tools Rate Thread

Assignment of a VBA expression

 
 
ydbc
Guest
Posts: n/a
 
      20th Jan 2010
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
--
ydbc
 
Reply With Quote
 
 
 
 
Stefan Hoffmann
Guest
Posts: n/a
 
      20th Jan 2010
hi,

On 20.01.2010 13:09, ydbc wrote:
> 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 <--
 
Reply With Quote
 
Daryl S
Guest
Posts: n/a
 
      21st Jan 2010
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.
--
Daryl S


"ydbc" wrote:

> 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
> --
> ydbc

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Expression Web 2.0 and other Expression Web products are on sale at the Microsoft Online Store Tina Clarke Microsoft Frontpage 5 4th Jul 2009 02:27 AM
How to compile a c# Lambda expression to a System.Linq.Expression. Colin Han Microsoft C# .NET 2 16th Oct 2008 09:06 AM
Getting #Error when I include an expression in a second expression Steve D Microsoft Access Queries 7 3rd Oct 2008 07:12 PM
DataSet.Merge with Column.Expression. expression not =?Utf-8?B?R2llZHJpdXM=?= Microsoft ADO .NET 4 12th Jan 2005 09:45 AM
Validation Expression help (for expression that works on server but not client) Brad Microsoft ASP .NET 4 13th Mar 2004 12:45 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:06 PM.