Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Button reference 1

Status
Not open for further replies.

matrixindicator

IS-IT--Management
Sep 6, 2007
418
BE
sorry, I can't get out.

I have a number of buttons, they can be numbered like
btn1, btn2, btn3, btn15, ...

With the event OnClick on a button is a macro activated that run a procedure, this is a function.

Code:
testfunct(btn1.caption)
 
Function testfunct(ctl As String)
Forms![14]!txtIDART = ctl

End Functionc

Above is working, but the name of the function is here fixed. How can I say take the actual button. The name of the button is variable.
 

Is that something you are going after?
Code:
Option Explicit

Private Sub btn1_Click()
Call testfunct(btn1)
End Sub

Private Sub btn2_Click()
Call testfunct(btn2)
End Sub

Private Sub btn3_Click()
Call testfunct(btn3)
End Sub

Function testfunct(ctl As Control)

MsgBox "You clicked on " & ctl.Name & " with the caption of " & ctl.Caption

End Function

Have fun.

---- Andy
 
It was not completely the solution, but it set me on thinking ans testing and now it works. I set a function direct after the OnClick event and put as parameter the name of the button.

thanks

Code:
'create button with function
Dim knop As String
knop = "=testfunct([" & "btn" & rst!IDPL & "])"
EigenControl.OnClick = knop
'use the function
OnClick =testfunct([btn2])
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top