Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics GP (Archived)

How to add Sleep command in vba macro for Great Plains

Posted on by 60

Hi,

I am using VB.Net windows application to run the vba macro to Post EC in the Great Plains. Because of process taking longer time (about 6-7 min) and macro is trying to close GP  then it is giving error  So I wanted to wait in  the sleep mode duing the process before close command about 10 mins. How can I add the Sleep command which is available for VBA macros? Please let me know if you have any other thoughts......

Thanks

Vikram 

 

*This post is locked for comments

  • winthropdc Profile Picture
    winthropdc on at
    Re: Re: Re: Re: Re: How to add Sleep command in vba macro for Great Plains

    TEMP.MAC is a macro created by the dexterity scripty and then run.

    I believe you should be able to use a similar method from VB.Net to access the continuum integration library.

    I have not done it myself. 

    David Musgrave [MSFT]
    Escalation Engineer - Microsoft Dynamics GP
    Microsoft Dynamics Support - Asia Pacific

    Microsoft Dynamics (formerly Microsoft Business Solutions)
    http://www.microsoft.com/Dynamics

    mailto:David.Musgrave@online.microsoft.com
    http://blogs.msdn.com/DevelopingForDynamicsGP

    Any views contained within are my personal views and not necessarily Microsoft policy.
    This posting is provided "AS IS" with no warranties, and confers no rights. 

  • Vikram Kolli Profile Picture
    Vikram Kolli 60 on at
    Re: Re: Re: Re: How to add Sleep command in vba macro for Great Plains

    Hi David,

    I did not used Customisation Maintenance to Import, I  have used tools/customize/Visual Basic Editor and I have selected Microsoft Dynamics_GP and from there I selected file/Import.

    Ok, now I am using your code. and compiled module. As you know I need to run my macro from Windows vb.net app. Do I need to change my code or macro to to execute this Window_AfterClose() or GP automatically closes ones the process completes.

    I noticed TEMP.MAC in the code what is that? Is it built-in macro?

     If I need change my macro can you please let me know what change I have to made.

    The following macro I am using but I am getting error because the process did not completes.The process is taking 7-8 mins.

     Logging file 'Login and Transfer ORDERS and Allocate.log'
    # DEXVERSION=9.00.0073.0 2 2
    CheckActiveWin dictionary 'default'  form Login window Login
      TypeTo field 'User ID' , 'RPMonkey'
      MoveTo field Password
     TypeTo field Password , 'automate'
      CheckActiveWin dictionary 'default'  form Login window Login
      MoveTo field 'OK Button'
      ClickHit field 'OK Button'
      NewActiveWin dictionary 'default'  form 'Switch Company' window 'Switch Company'
      ClickHit field '(L) Company Names' item 1  # 'eCommerce'
      MoveTo field 'OK Button'
      ClickHit field 'OK Button'
      CommandExec dictionary 'default'  form 'Command_Purchasing' command 'POP_Batch_Entry'
    NewActiveWin dictionary 'default'  form 'POP_Batch_Entry' window 'POP_Batch_Entry'
      MoveTo field 'Lookup Button 1'
      ClickHit field 'Lookup Button 1'
    NewActiveWin dictionary 'SmartList'  form 'Batch_Lookup' window 'Batch_Lookup'
      MoveTo field 'Select Button'
      ClickHit field 'Select Button'
    NewActiveWin dictionary 'default'  form 'POP_Batch_Entry' window 'POP_Batch_Entry'
      MoveTo field 'Post Button'
      ClickHit field 'Post Button'
    ActivateWindow dictionary 'default'  form 'Progress_Control' window 'Progress_Window'
    # Print To File:  'POP Receivings Posting Journal'
    # Print To File:  'POP Receivings Distribution Detail'
    # Print To File:  'POP Invoice Cost Variance Journal'
    # Print To File:  'POP Back Ordered Items Received'
    NewActiveWin dictionary 'default'  form 'POP_Batch_Entry' window 'POP_Batch_Entry'
    # Print To File:  'General Posting Journal'
    CloseWindow dictionary 'default'  form 'POP_Batch_Entry' window 'POP_Batch_Entry'
      CommandExec dictionary 'default'  form 'Command_Sales' command 'SOP_Batch_Entry'
    NewActiveWin dictionary 'default'  form 'SOP_Batch_Entry' window 'SOP_Batch_Entry'
    CloseWindow dictionary 'default'  form 'SOP_Batch_Entry' window 'SOP_Batch_Entry'
    CheckActiveWin dictionary 'default'  form syReminders window syReminders
      MoveTo field '(L) btnClose'
      ClickHit field '(L) btnClose'
    ActivateWindow dictionary 'default'  form Toolbar window 'Main_Menu_1'
      CommandExec form BuiLtin command cmdQuitApplication

    Thank you for your help

    Vikram

     

  • winthropdc Profile Picture
    winthropdc on at
    Re: Re: Re: How to add Sleep command in vba macro for Great Plains

    Hi Vikram

    Can I assume that you used Customisation Maintenance to Import and that you only have the code imported and not the entire package?

     

    Code Example

    Option Explicit

    Private Sub Window_AfterClose()
        'Dim CompilerApp As New Dynamics.Application
        Dim CompilerApp As Object
        Dim CompilerMessage As String
        Dim CompilerError As Integer
        Dim Commands As String
       
        ' Create link without having reference marked
        Set CompilerApp = CreateObject("Dynamics.Application")
       
        Commands = ""
        Commands = Commands & "local integer l_file_id; " & vbCrLf
        Commands = Commands & "local string pathname; " & vbCrLf
        Commands = Commands & "pathname = Path_GetForApp(1) + ""TEMP.MAC""; " & vbCrLf
        Commands = Commands & "l_file_id = TextFile_Open(pathname, 0, 0); " & vbCrLf
        Commands = Commands & "TextFile_WriteLine(l_file_id, ""CommandExec form BuiLtin command cmdQuitApplication""); " & vbCrLf
        Commands = Commands & "TextFile_Close(l_file_id); " & vbCrLf
        Commands = Commands & "if File_Probe(pathname) then " & vbCrLf
        Commands = Commands & "  run macro pathname; " & vbCrLf
        Commands = Commands & "end if; " & vbCrLf
       
        ' Execute SanScript
        CompilerError = CompilerApp.ExecuteSanscript(Commands, CompilerMessage)
        If CompilerError <> 0 Then
            MsgBox CompilerMessage
        End If
    End Sub

     

    David Musgrave [MSFT]
    Escalation Engineer - Microsoft Dynamics GP
    Microsoft Dynamics Support - Asia Pacific

    Microsoft Dynamics (formerly Microsoft Business Solutions)
    http://www.microsoft.com/Dynamics

    mailto:David.Musgrave@online.microsoft.com
    http://blogs.msdn.com/DevelopingForDynamicsGP

    Any views contained within are my personal views and not necessarily Microsoft policy.
    This posting is provided "AS IS" with no warranties, and confers no rights. 

     

  • Vikram Kolli Profile Picture
    Vikram Kolli 60 on at
    Re: Re: How to add Sleep command in vba macro for Great Plains

    Hi David,

    Thank you for your information.

    I have imported the SY_Check_Links package into the GP.

    I try to the next step which is
    Go into the VBA editor (Tools >> Customise >> Visual Basic Editor) and compile the Microsoft Dynamics GP project (Debug >> Compile Microsoft Dynamics GP.

    I have got the following error:

    Complie error:

    Expected: line number or label or statement.

    What could be the problem...

    The extrated Module is

    <Component Name="SY_Check_Links" ProductId="0" Object="VBAForm" >
    VBAForm "SY_Check_Links"
    {
            Windows
            {
                    Window "Check Links"
                    {
                            Code "Option Explicit"

    Private Sub Window_AfterClose()
        'Dim CompilerApp As New Dynamics.Application
        Dim CompilerApp As Object
        Dim CompilerMessage As String
        Dim CompilerError As Integer
        Dim Commands As String
       
        ' Create link without having reference marked
        Set CompilerApp = CreateObject(\"Dynamics.Application\")
       
        Commands = \"\"
        Commands = Commands & \"local integer l_file_id; \" & vbCrLf
        Commands = Commands & \"local string pathname; \" & vbCrLf
        Commands = Commands & \"pathname = Path_GetForApp(1) + \"\"TEMP.MAC\"\"; \" & vbCrLf
        Commands = Commands & \"l_file_id = TextFile_Open(pathname, 0, 0); \" & vbCrLf
        Commands = Commands & \"TextFile_WriteLine(l_file_id, \"\"CommandExec form BuiLtin command cmdQuitApplication\"\"); \" & vbCrLf
        Commands = Commands & \"TextFile_Close(l_file_id); \" & vbCrLf
        Commands = Commands & \"if File_Probe(pathname) then \" & vbCrLf
        Commands = Commands & \"  run macro pathname; \" & vbCrLf
        Commands = Commands & \"end if; \" & vbCrLf
       
        ' Execute SanScript
        CompilerError = CompilerApp.ExecuteSanscript(Commands, CompilerMessage)
        If CompilerError <> 0 Then
            MsgBox CompilerMessage
        End If
    End Sub"
                            EventMode "0"
                            Fields
                            {
                            }
                            Title "CheckLinks"
                    }
            }
    }
    </Component>
     

     

    Thanks

    Vikram 

     

     

     

     

     

     

  • winthropdc Profile Picture
    winthropdc on at
    Re: How to add Sleep command in vba macro for Great Plains

    Hi Vikram

    Please have a look at the following blog post as it should resolve your issue:

    http://blogs.msdn.com/developingfordynamicsgp/archive/2008/09/10/running-a-macro-to-automatically-close-gp-example.aspx 

    David Musgrave [MSFT]
    Escalation Engineer - Microsoft Dynamics GP
    Microsoft Dynamics Support - Asia Pacific

    Microsoft Dynamics (formerly Microsoft Business Solutions)
    http://www.microsoft.com/Dynamics

    mailto:David.Musgrave@online.microsoft.com
    http://blogs.msdn.com/DevelopingForDynamicsGP

    Any views contained within are my personal views and not necessarily Microsoft policy.
    This posting is provided "AS IS" with no warranties, and confers no rights. 

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans