Trigger a command button event

hog

Senior Contributor
Joined
Mar 17, 2003
Messages
984
Location
UK
I have some code in a command button which I would like to call from a sub, is this possible?

If so what do I put in the arguments?

Code:
Private Sub cmdNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdNext.Click

Thnx
 
Just so I understand, you have code in the cmdNext, that you would also like to use from somewhere else?

I would make another sub

Private sub sharedsubwhatever(intVariable as int) ' only if you need to pass some variable though
'code
end sub

then call this sub in the cmdnext and from the other sub that needs to use the same code

Private Sub cmdNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdNext.Click
sharedsubwhatever(1)
end sub

private sub subthatneedssamecode
sharedsubwhatever(1)
end sub
 
hog,

you can call your cmdNext_click eventusing the following

cmdNext_click(sender,e)

BUT this is considered lazy programming. The solution provided by techmanbd is the cleaner way of programming.
 
Back
Top