Click events - catch for multiple fields

kirkm

Registered User.
Local time
Today, 20:44
Joined
Oct 30, 2008
Messages
1,257
I have a Form in datasheet mode and want the same click event for about 100 fields.
The field name or index number that's clicked should be passed in.

Can I do this without writing 100 On_Click event procedures ?

Thanks.
 
I don't think so. Each control name must be unique,therefore each will have its own on_click. You can make each call a common function so you don't have to write 100 routines if they all do the same thing.
 
Ok thanks.. I'll get typing !
I recall some way in either Excel or VB.Net but can't remember it !
 
From Googling I found some ideas. one is

Code:
Private Sub Form_Load()
Dim ctl As Control
Dim mdl As Module
Dim frm As Form
Set frm = Me
Set mdl = Me.Module
Dim lngreturn
For Each ctl In Me.Controls
If ctl.ControlType = acTextBox Then
  '  Debug.Print ctl.Name
        If InStr(ctl.Name, "Week") > 0 Then
            ctl.ColumnWidth = 300
            lngreturn = mdl.CreateEventProc("Click", ctl.Name)
            mdl.InsertLines lngreturn + 1, "=kClick()"
        End If
End If
Next
Set frm = Nothing
Set mdl = Nothing
End Sub
But I get an error "invalid" on line lngreturn =...

I'm not familiar with this. should it work ?
 
I should add if I change the On Click property from [Event Procedure] to
=kClick()
I can then pick up Me.ActiveControl.Name in the function.
 

Users who are viewing this thread

Back
Top Bottom