VBA Help - "_A...
 

Subscribe now and choose from over 30 free gifts worth up to £49 - Plus get £25 to spend in our shop

[Closed] VBA Help - "_AfterUpdate" event for mulitple controls on Access form

5 Posts
5 Users
0 Reactions
127 Views
Posts: 2823
Free Member
Topic starter
 

I've got an Access Form with about 10 text boxes containing numbers that add up to a total value held in an 11th text box. I then need to check the value in textbox11 to make sure it doesnt exceed another value (held in box 12).

I've attached code to each of the 10 text boxes to update the total in 11, but there must have been an easier way than this:

Private Sub txtInitialDrop1_Vol_AfterUpdate()
Call fCheckInitialVolume
End Sub

Private Sub txtInitialDrop2_Vol_AfterUpdate()
Call fCheckInitialVolume
End Sub

Private Sub txtInitialDrop3_Vol_AfterUpdate()
Call fCheckInitialVolume
End Sub

Private Sub txtInitialDrop4_Vol_AfterUpdate()
Call fCheckInitialVolume
End Sub

etc etc

Is there a way I can use just one _AfterUpdate event, by referencing all 10 text boxes as some sort of Collection maybe?

cheers


 
Posted : 22/08/2013 1:31 pm
Posts: 0
Free Member
 

Not that I know of.

<ever helpful me>

<and I do use Access and VBA loads>


 
Posted : 22/08/2013 2:34 pm
Posts: 1642
Free Member
 

Wouldn't adding a 'check total' button to the form do?


 
Posted : 22/08/2013 2:52 pm
Posts: 0
Free Member
 

Agreed ^. You need to monitor for 10 events, so 10 event handlers.


 
Posted : 22/08/2013 2:53 pm
Posts: 0
Free Member
 

I'm not sure there is a way around having an update event on each textbox but an alternative to your approach you could call your code to run on the form's afterupdate event rather than that of the individual text boxes and then simply put a me.refresh in the afterupdate event of the individual text boxes.

Only real advantage of this over what you're doing already though is that you only need to maintain the reference to your total check in one place rather than 10.


 
Posted : 22/08/2013 2:59 pm
Posts: 2823
Free Member
Topic starter
 

Thanks guys


 
Posted : 27/08/2013 9:11 pm