SidFishes
asked on
Generic Onclick event for form of Checkboxes
My vba skills are a little rusty these days so...
I have a form with 40 checkboxes. on update of any one of these I want to fire an event which runs a function
fnUpdateIngredAllergen Me.IngredientID, Me.ActiveControl.Name, Me.ActiveControl.value
which passes that info to a stored procedure.
Currently I have
Private Sub chkDairyCont_Click()
fnUpdateIngredAllergen Me.IngredientID, Me.ActiveControl.Name, Me.ActiveControl.value
end sub
for each checkbox. Well I've actually just got it set for the one right now..
My question is: is there a way to avoid coding that OnClick for every control. Is there something that can determine which control was clicked (ala Me.ActiveControl.Name) and fire a generic event.
ie
function clickListenerTriggeredbySo mething()
fnUpdateIngredAllergen Me.IngredientID, magicallydeterminecontrolt hatwasclic ked, controlthatwasclicked.valu e
end function
I'm thinking no....
I have a form with 40 checkboxes. on update of any one of these I want to fire an event which runs a function
fnUpdateIngredAllergen Me.IngredientID, Me.ActiveControl.Name, Me.ActiveControl.value
which passes that info to a stored procedure.
Currently I have
Private Sub chkDairyCont_Click()
fnUpdateIngredAllergen Me.IngredientID, Me.ActiveControl.Name, Me.ActiveControl.value
end sub
for each checkbox. Well I've actually just got it set for the one right now..
My question is: is there a way to avoid coding that OnClick for every control. Is there something that can determine which control was clicked (ala Me.ActiveControl.Name) and fire a generic event.
ie
function clickListenerTriggeredbySo
fnUpdateIngredAllergen Me.IngredientID, magicallydeterminecontrolt
end function
I'm thinking no....
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You can select all checkboxes at once (using shift key or by dragging the mouse) and display the properties- you can then enter the expression just once and it will be applied to all the selected controls.
ASKER
hmmm getting a byRef error on Public Function clickListener() As Boolean
Works for me ... and tested.
You can drop the As Boolean. And post exactly what you have.
mx
You can drop the As Boolean. And post exactly what you have.
mx
ASKER
byref error on x to be precise
ASKER
bah ok that's a byref passing to the function args... Looks like it will work... back in a few
Yes ... get rid of ByRef ...
mx
mx
ASKER
I had to declare x,y & z individually so they would pass to the function which fixed the byRef (or I guess I could have removed the declarations in the function but I'd rather be explicit)
Public Function clickListener()
Forms.frmIngredientAllerge ns.SetFocu s
Dim x As Integer, y As String, z As Boolean
x = Screen.ActiveForm("Ingredi entid")
y = Screen.ActiveControl.Name
z = Screen.ActiveControl.value
fnUpdateIngredAllergen x, y, z
End Function
good stuff
My ctrl-c & ctrl-v thank you ;)
Public Function clickListener()
Forms.frmIngredientAllerge
Dim x As Integer, y As String, z As Boolean
x = Screen.ActiveForm("Ingredi
y = Screen.ActiveControl.Name
z = Screen.ActiveControl.value
fnUpdateIngredAllergen x, y, z
End Function
good stuff
My ctrl-c & ctrl-v thank you ;)
"I had to declare x,y & z individually"
Sure ... what I did was just ... 'conceptual' :-)
mx
Sure ... what I did was just ... 'conceptual' :-)
mx