Command Buttons - Automate Click

Is there any way to simulate a click on a button through code? Basically what I need is the following: On the Job List the OK button’s PushAction is LookupOk. I have another button Sort (on the Job List form) that (on its onPush Trigger) run’s some code first, then if it changed the current record on the Job List, I need to close the Job List Form with LookupOk. I can’t figure out how to return LookupOk without having to use the PushAction property of a control (which will not work in these circumstances). Any Ideas? Thanks, Mark. Edited by - msraetsen on 2001 Nov 24 16:28:17

Hi Mark. You can write the code on the onPush Trigger of the button itself and depending on the outcome Decide wether you want to display the form or not. Eg: if X = true then frmJobList.runmodal; hope this helps. NGP/NCSD

Hi Vishal, I’m not sure I understand you’re solution. If you wouldn’t mind clarifying a bit that would be great. Also note, I’ve modified my original post and hopefully it is a bit clearer too. Thanks, Mark.

You could try setting the pushaction to something else!


if form.runmodal(form::whatever,somerecord) = action::OK then
  <The OK Bottom was pressed>

//Henrik Helgesen -: KISS::Keep it Simple, Stupid :-

Thanks for the reply Henrik… however, that doesn’t solve the problem. It only changes the value I need to return (which is the problem). I thought that we should somehow be able to return the Action in code either directly or indirectly (by simulating a click on the OK button for example). Mark. Edited by - msraetsen on 2001 Nov 26 19:43:48

How about creating a global on the form that indicates the button pressed. Your OK button can then set the value of this global just prior to closing the form. After RUNMODAL returns, you can call a function on the form that will pass the value of this global back to the callng environment.

Thanks for the reply Jack… the problem with setting a global is that then I have to change all of the forms where Job List is called from (which I am really trying to avoid because of the number of places it is used). If it is not possible to return an Action other than in a PushAction property then I’ll have to do this or something similar. I just can’t understand how it can be that we cannot set the return value of a form in code or “make” a button be clicked in code??? Mark.

When the OK-button always has to be pushed, after the sort-button is pushed, there is a workaround. Set the PushAction-property, of your sort-button, to LookupOK. The code in the OnPush-Trigger will first be executed before the form returns the active record. Hope it helps you, Reijer.

Thanks Reijer… I had tried that before and received an error:

"'Job List' cannot be closed, because it is locked by 'Status Bar'.
Please finish 'Status Bar' before closing."

Now, I’ve realized (finally) that this only happens when I wait for a SHELL to finish. i.e in my OnPush trigger for my sort button I call:

rc := SHELL(someprogram);

If I omit rc (i.e. don’t wait for completion it works fine, but I need to wait for completion)… anyways… thanks to everyone and sorry for the misleading post. I’ll now make a new post with my revised problem . But if anyone does know of a way to return an Action or simulate a button click in code I’d still be interested because it would still solve my problem. Thanks, Mark. Edited by - msraetsen on 2001 Nov 27 23:06:08