Ask Your Question
0

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

asked 2017-07-29 15:45:11 +0100

baseplodder gravatar image

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!

edit retag flag offensive close merge delete

Comments

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.

EasyTrieve gravatar imageEasyTrieve ( 2017-07-29 18:08:18 +0100 )edit

1 Answer

Sort by » oldest newest most voted
0

answered 2017-07-29 20:06:48 +0100

Ratslinger gravatar image

updated 2017-07-29 20:55:39 +0100

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 ✔ (upper left area of answer).

edit flag offensive delete link more

Comments

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!

baseplodder gravatar imagebaseplodder ( 2017-07-30 13:24:39 +0100 )edit

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?

baseplodder gravatar imagebaseplodder ( 2017-08-08 15:46:06 +0100 )edit

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.

Ratslinger gravatar imageRatslinger ( 2017-08-08 16:08:49 +0100 )edit
Login/Signup to Answer

Question Tools

Stats

Asked: 2017-07-29 15:45:11 +0100

Seen: 349 times

Last updated: Jul 29 '17