one on_click function for more than one control

awrude

Registered User.
Local time
Today, 11:19
Joined
May 23, 2013
Messages
18
I do not know if this is possible or how to begin trying to figure it out. I have many controls that do the same function. I have it set up that when they click on a textbox the date automatically populate the control. I then have it so if they click it again, they can delete the date or keep it. I have the textboxes labelled the same (dteMT0, dteMT1, etc...). Rather than have to do an on_click for each of these, is there a way I can set up one on_click function to work for all?

I have been using the following code for quite a bit and it seems to work but not sure if it would for this...


Me.Controls("optlvl" & CStr(a)).Value

where 'a' is an integer in a for next loop
 
IRather than have to do an on_click for each of these, is there a way I can set up one on_click function to work for all?

Sure, implement your own new custom event on the form, and place in each of the control's events 1 LOC to forward that event to your custom event. Example:


Code:
'Record double-click behavior
Private Sub fldid_DblClick(Cancel As Integer)

  Call Me.PartEdit_Click

End Sub

Private Sub fldpartnumber_DblClick(Cancel As Integer)

  Call Me.PartEdit_Click

End Sub

Private Sub fldtitle_DblClick(Cancel As Integer)

  Call Me.PartEdit_Click

End Sub

Private Sub fldrev_DblClick(Cancel As Integer)

  Call Me.PartEdit_Click

End Sub

Private Sub fldver_DblClick(Cancel As Integer)

  Call Me.PartEdit_Click

End Sub

'And so on....
You must make your custom event a Public event. So where Private appears in the events which Access/VBA adds automatically for you when you create a new event via the Access design more UI, place Public in that spot.

Code:
Public Sub PartEdit_Click()

End Sub
 

Users who are viewing this thread

Back
Top Bottom