PDA

View Full Version : Solved: Controlling command buttons of forms



ibgreat
09-09-2008, 03:34 PM
I have 2 forms (form1, form2) that can open another form (form3). Within form3 the user selects a value from a list box. When form3 is opened from form1 or form2, a select button becomes visible on form3. Can I create a procedure in form1 and form2 that responds to clicking the select button (the code will return values from form3 to the form that opened it)?

Ideally, I don't want the code to be in form3 because the data will be returned to whatever form opened it (there could be more later). I realize I could have several buttons on form3 and have each correspond to a particluar form and only be visible when that form calls it. But this would seem to creating redundant objects. Can I do this cleanly?

Also, setting the visible property for the select button on form3 from form1 is not working. The OnLoad event on form3 sets teh visible property to false. What I think is happening is that code on form1 to set it to visible is running prior to form3 loading completely.

CreganTur
09-10-2008, 05:38 AM
The OnLoad event on form3 sets teh visible property to false. What I think is happening is that code on form1 to set it to visible is running prior to form3 loading completely.
Remove the OnLoad event that sets the button to .visible = False. What's happening is that your Form (1 or 2) is setting the button to visible... but then the Load event is then making the button invisible.

Make the button invisible by using the property sheet instead so that the Forms (1 or 2) will be able to correctly set the .visible property. Then make use of the Close Event to ensure the button goes invisible again when you're done:
If Me.Select.Visible = True Then
Me.Select.Visible = False
End If


Ideally, I don't want the code to be in form3 because the data will be returned to whatever form opened it (there could be more later).
The code needs to be in Form3, but you can use the IsLoaded property to check to see which other form is loaded(currently open[form1 or form2]). Then you can use an If statement (or SelectCase statement, whichever meets your needs better) to have the code interact with the correct form.

HTH:thumb

ibgreat
09-10-2008, 06:33 AM
Make the button invisible by using the property sheet instead so that the Forms (1 or 2) will be able to correctly set the .visible property. Then make use of the Close Event to ensure the button goes invisible again when you're done:
If Me.Select.Visible = True Then
Me.Select.Visible = False
End If

Ah, that makes perfect sense.



The code needs to be in Form3, but you can use the IsLoaded property to check to see which other form is loaded(currently open[form1 or form2]). Then you can use an If statement (or SelectCase statement, whichever meets your needs better) to have the code interact with the correct form.

HTH:thumb

This makes sense to. Your reply makes me think more about the application of having the button do different things depending on which form is open. If the user leaves multiple forms open this could be an issue. Could I use a funtion for OnLostFocus (instead of procedure) that would return a value to distinguish the form that called the form 3 to be loaded? Could the value be passed between the code of the forms? I haven't done to much with passing values between functions within Access so I am good with how flexible they are.

CreganTur
09-10-2008, 06:45 AM
If the user leaves multiple forms open this could be an issue.
Simple answer: don't allow them to leave forms Open that aren't needed. Whenever I have a button that calls another Form, I have the first Form close as the second one opens- I do this for the Forms that they don't need opened. This reduces the needed resources a little, and it allows me to control the User's interaction with the Database.

ibgreat
09-10-2008, 07:44 AM
Simple answer: don't allow them to leave forms Open that aren't needed.

Yes, I do this. I suppose I am anticipating that I won't always be able to do this. We'll see if I can keep it this simple. If I can't I will repost.

As always, thanks! :thumb