Button click form seperate form

Cheeky

New member
Local time
Today, 16:01
Joined
Nov 16, 2000
Messages
5
Is there a simple piece of VB I can add to a button in one form which has the effect of clicking a button in a different form?

Thanks in advance.

Jim.
 
Hi Cheeky

Yes and No ... or perhaps/probably!

I don't know of a way to make a command button one form actually click another button on a different form ... and I don't think you need to do it that way. Instead the coding behind the button on form 2 can be copied across and used within the coding in form 1.

However, you need to be aware of the fact that form2 would need to be open at the time (so you would need to run some code to check that ... an IsOpen Function) and you would need to make sure that the things referrred to by button 1 that originally came from button 2 were correctly referenced (e.g. something like Me!txtFirstName would become Forms!frmMyForm2!txtFirstName)

Thinking about this a bit more I suppose you could make the Procedure called by button2 from a Private Sub to a Public Sub. Then perhaps you could call that procedure from button 1 e.g.

Call Button2_Click()

Not sure I would recommend this, though, as you would need to still check that Form2 was open (using an IsOpen function) ... and I wonder what it is that you want to achieve and whether this is the best way to go about it.

So Yes/No/Perhaps/Probably/Better Not! .. that's my answer to your question!

HTH

Rich Gorvin

[This message has been edited by Rich@ITTC (edited 09-21-2001).]
 
Rich,

Thanks for your reply, I have not tried it yet but I suspect that what you say should work fine. What I am actually doing is clicking a button to open the second form and then in that code clicking a button on the second form so in theory the form is open already. I'll give it a try and see.
 
As Rich has already said you can make the procedure on the 'other' form public(replace the private keyword in the event with public). Once done I think you should be able to click the button using:

Form_FormName.btnName_Click

I am not sure how it will accept control references such as Me! and especially ones that refer to the active form though.

Best of luck.

Ian
 

Users who are viewing this thread

Back
Top Bottom