Developing for Microsoft Dynamics GP by David Musgrave (Australia) and the Microsoft Dynamics GP Developer Support Team (USA)Syndicated From: http://blogs.msdn.com/b/DevelopingForDynamicsGP/
Click on the link to see the full About Page.
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:
SendKeys "% n"
VBA Code Example for Customer Maintenance window ' ** Uncomment the line below to use early binding, requires ' ** reference to Dynamics Continuum Integration Library ' ** Early binding allows Intellisense to work on CompilerApp object 'Dim CompilerApp As New Dynamics.Application ' ** Comment out the line below to use early binding Dim CompilerApp As Object Dim CompilerMessage As String Dim CompilerError As Integer Dim CompilerCommand As String ' Create link without having reference marked ' ** Comment out the line below to use early binding Set CompilerApp = CreateObject("Dynamics.Application") CompilerCommand = "" CompilerCommand = CompilerCommand & "Window_SetState(window RM_Customer_Maintenance of form RM_Customer_Maintenance, WINDOW_STATE_MINIMIZED);" & vbCrLf ' Execute SanScript ' ** Change Product ID to value from Dynamics.set for appropriate product CompilerApp.CurrentProductID = 0 ' DYNAMICS ' ** Uncomment the line below if wanting to address fields added to modified window 'CompilerApp.CurrentProduct = CompilerApp.CurrentProduct & "!Modified" CompilerError = CompilerApp.ExecuteSanscript(CompilerCommand, CompilerMessage) If CompilerError <> 0 Then MsgBox CompilerMessage End If Set CompilerApp = Nothing
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:
Dexterity On-the-fly Macro Code Example local integer l_file_id; local long l_result; local string macroname; local boolean l_boolean; {Create & Run Macro File} pragma(disable warning LiteralStringUsed); macroname = GetTempDir() of form coLetterWizard + "MBS_TEMP.MAC"; l_file_id = TextFile_Open(macroname, 0, 0); l_result = TextFile_WriteLine(l_file_id, "NewActiveWin dictionary 'Microsoft Dynamics GP' form DiaLog window DiaLog "); l_result = TextFile_WriteLine(l_file_id, " ClickHit field OK "); l_boolean = TextFile_Close(l_file_id); pragma(enable warning LiteralStringUsed); run macro macroname; { Simulate Dialog opening } warning "This is a System Dialog."; { Delete temporary macro file when no longer needed } { This code must execute after macro has closed dialog } if File_Probe(macroname)then File_Delete(macroname); end if;
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.
VBA Window_BeforeModalDialog Code Example Private Sub Window_BeforeModalDialog(ByVal DlgType As DialogType, PromptString As String, Control1String As String, Control2String As String, Control3String As String, Answer As DialogCtrl) Select Case PromptString Case "Do you want to delete this record?" Answer = dcButton1 Else End Select End Sub
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.
David