Base macro to switch enable/dis-enabled property of push button

I am a beginner in macro-programing in BASE and have a seemingly trivial problem which I cannot solve and cannot find discussed elsewhere in this forum. I would therefore appreciate any help the forum can give me.

I wish to write a macro which opens a form and changes the status of a field in that form. In particular I have a form (Form A) which contains two press buttons (A1 and A2). Associated with each button is a macro (M1 and M2 respectively), both of which open a second form (Form B) which contains a press button (B1). Up to this point I have written code that works. But what I cannot do is the following: the code of M1 and M2 must differ because M1 should enable the button B1, whilst M2 should change the background color of B1 (from say. Gray2 to Cyan or a different RGB Hex code) and should dis-enable B1 so that it cannot be pressed. Can someone tell me what this code difference should be?

As Form B can only be reached from the two buttons on Form A I presently do not have to convert the enabled/dis-enabled status of B1 back to a default value when Form B is exited, but it would be nice to know how this might be achieved if required in the future!

I find your Q sort of confusing. I get that you have a formA w/ 2 buttons which open A1->M1->B->enable B1, and A2-M2->B->change color of B1. But what is unclear to me is the rest.

Hello,

If you think this is trivial, you are in for a real surprise down the road about macros and their complexity. You cannot find this in the forum because you don’t have the background knowledge to know what to look for. I say this only to let you know what is ahead and not as any reflection on your abilities.

You are trying to change something from one form in another form which is not yet available. To accomplish this, Form B needs to know what Form A requested but when Form B is opened Form A is probably closed already. So Form a should store the info in Global variables. This retains the information even when a sub has completed. When Form B is opened, There should be a macro tied to the Open Document event of the form (Tools->Customize->Events). This macro can then read the global variables set by Form A and take appropriate action.

When Form B is closing, another macro to reset B1 on Form B to default values. This can be tied to another form event such as Document is going to be closed.

There are other ways to go about this (always more than one answer), but this will probably be the easiest.

Edit:

To make this a bit easier, here is a sample: ButtonChangeForms.odb

If this answers your question please click on the :heavy_check_mark: (upper left area of answer).

I very much appreciate your help Ratslinger and thank you for the ButtonChangeForms.odb. I spent some time examining and experimenting with the macro and feel I now have made a significant step forward in understanding the processes involved and the code needed. Again many thanks!

I notice that you bound the subroutine FormClose to the ‘View is going to be closed’ event rather than to the ‘Document closed’ or ‘Document is going to be closed’ event. Could you tell me the difference between these options or point me towards literature where the different event options are better explained? For example, are these LO/OO options mirrored on options in MS Access where the documentation might be better?

Documentation on these form events is hard to find. Most of my experience is by trial and error. You certainly wouldn’t want to use "Document closed’ since you cannot reset anything so some is just logical. As far as Access, I have long put MS in my past. I have found it much easier to learn LO if I forget MS and Access. For macro reference manual, here is best I can point to - OOME.