Recently I responded to a question on a newsgroup asking how to minimise a window from VBA (Visual Basic for Applications).
The short answer is that it is not possible. But just because a Microsoft Dynamics GP window VBA object does not expose any methods or properties for the window state does not mean we have to give up.
Answering the post made me think about how we can overcome limitations by thinking outside of the box. What other methods can we use to achieve the desired results?
In this case there were two possible solutions:
- Sending the keystrokes with the VBA SendKeys command:
SendKeys “% n” ‘ Alt-Space, n
- Using pass through sanScript to ask Dexterity to change the window state for you:
VBA Code Example for Customer Maintenance window
Note: The method of calling Dexterity sanScript from VBA using the Continuum Integration Library is not supported.
Another issue recently discussed on the blogs is the handling of modal dialogs. Dexterity does not have any triggers which can be registered against a modal dialog. This means that if you are attempting to drive the user interface from a customisation and a modal dialog opens your code is now stuck waiting for a user to dismiss the dialog.
Again there are methods that can be used to resolve this issue:
In the Integrating with Third Party Dictionary materials (available from here) a method of using an on-the-fly macro to control system dialogs is discussed. Here is some example code of running a macro to close a dialog. The macro must be run before the dialog is opened.
Dexterity On-the-fly Macro Code Example
Note: As macros run after the completion of background processes this method can have delay issues when there are background processes or reports being executed.
Another method, discussed by Sivakumar on his blog post is to use VBA to handle the dialog for us as VBA does have events for modal dialogs.
VBA Window_BeforeModalDialog Code Example
Tip: Use a Breakpoint on the Select Case statement when you first write the code, then you can enter ? PromptString into the Immediate window (select View >> Immediate Window if it is not currently displayed) and then copy and paste the exact wording for the dialog into your code.
The reason for this post is to show how using other methods such as SendKeys, macros and hybrid code from more than one language can allow developers to get past limitations in the development environment.
The take away message from this post is simple:
Don’t be afraid to think Outside of the Box.
25-Sep-2009: Added copy and paste tip for modal dialog handling.
06-Jan-2012: Fix typo in VBA Window_BeforeModalDialog script.