This is a reposting of an article I originally wrote on my Developing for Dynamics GP blog.
One of the customisations that I have heard requests for a number of times is to open the General Ledger Journal Entry (GL Transaction Entry) window’s scrolling window (grid) to its expanded state when the window is opened.
The method to make this happen is to use Visual Basic for Applications (VBA) to “press” the expand button as though the user has clicked on the button. However, when most people try to create this customisation, they end up receiving the following error message.
Run-time error ‘1008’: Unsafe Operation. An attempt was made to set a value into an application field which is disabled. This operation could compromise the integrity of the application.
This is because the “button” that we see is actually a non editable visual switch field used to display the graphic icon. The actual button that we need to press is an editable, but hidden field. Additional steps are needed to temporarily make the field visible so that it can be added to VBA.
The Knowledge Base (KB) articles below discuss this issue further and provide the steps to create the working customisation:
- Error message when you expand a scrolling window by using VBA in Microsoft Dynamics GP: “Run-time error ‘1008’: Unsafe Operation” (KB 951231)
- How to add a hidden field by using Modifier together with Visual Basic for Applications in Microsoft Dynamics GP (KB 951230)
There is another unsupported method which you can use achieve the same result. This method works by adding another visible field to VBA as a placeholder, and then editing the exported package to change the placeholder field details to the actual hidden field we need to reference.
- Log into Microsoft Dynamics GP. Click Transaction, click Financial, click General to display the Transaction Entry window.
- From the menu, click Tools, click Customize, click Add Current Window to Visual Basic.
- From the menu, click Tools, click Customize, click Add Field to Visual Basic. The mouse cursor will change.
- Click on the Expand Button to add the ‘Scroll Expand Switch’ field to VBA.Note: This is adding the wrong field to VBA, however the steps below will change the field to the correct one.
- Press the Esc key to turn off Add Field mode.
- Close the Transaction Entry window.
- From the menus, click Tools, click Customize, click Customization Maintenance.
- Select the GL_Transaction_Entry window and click Export to export it as a package.Note: Export a second package as a backup in case there is an issue with the changes made in the following steps.
- Open Notepad.exe and drag and drop the saved package file into the Notepad window.
- Find the reference to the Visual Switch ‘Scroll Expand Switch’ field, shown below: WindowField “Scroll Expand Switch”
ProgrammerName “Scroll Expand Switch”
- Edit the references to change the field to the desired hidden field, in our case the Push Button ‘Scrolling Window Shrink’. The Display name should be the same name with the spaces removed. The result is shown below: WindowField “Scrolling Window Shrink”
ProgrammerName “Scrolling Window Shrink”
- Close Notepad.exe and save the updated package.
- Back in Microsoft Dynamics GP, from the Customization Maintenance window, click Import, click Browse and click Local Files. Open the updated package, click OK and click OK again to the overwrite warning.
- From the menu, click Tools, click Customize, click Visual Basic Editor.
- In the Visual Basic Editor, locate the TransactionEntry (Window) module under the Microsoft_Dynamics_GP project. Double click on the module and enter the following code: Private Sub Window_AfterOpen()
ScrollingWindowShrink = 1
Me.Changed = False
Note: Setting the Me.Changed flag to False avoids the Save/Discard/Cancel dialog appearing when the window is closed without any changes being made.
- Return to Microsoft Dynamics GP.
- Click Transaction, click Financial, click General to re-open the Transaction Entry window. The window will now open without errors and with the scrolling window expanded.
Example code for v8.0, v9.0 & v10.0 is attached at the bottom of the article.
Please see the “Installation Instructions.txt” file in each version’s archive for more information.
This article was originally posted on the Developing for Dynamics GP Blog and has been reposted on http://www.winthropdc.com/blog.