cancel
Showing results for 
Search instead for 
Did you mean: 

Planning Function Macro Error Message

0 Kudos

Hi Guys

I assigned a Planning Sequence and a Plandatasave command to one button.

Sub Button1002_Click()

Dim lResult As Long

Dim lResult1 As Variant

lResult = Application.Run("SAPExecutePlanningSequence", "PS_1")

lResult = Application.Run("SAPExecuteCommand", "PlanDataSave")

End Sub

Unfortunately if an error occurs during the execution of the planning function the error message doesn't show up. It finally runs the Plandatasave functionality. If I run the Planning function on its own it shows the whole error message.

Does anyone knows how I can catch the entire error message of the Planning function and show it?

Sure, I could divide the execution of Planning function and Plandatasave to 2 different buttons. But the end user wants both functionalities in one button.

Accepted Solutions (1)

Accepted Solutions (1)

former_member523998
Participant
0 Kudos

You're saying you get the proper rejection message if you only one what at a time? What happens if you split the macro into two procedures and call them from a regular module? It looks like you're calling them from the Sheet Module which can sometimes influence behavior undesirably. You can also include an end in the macro to immediately alert the user if something didn't go write.

See Example:

Sub Button1002_Click()
    Call firstMacro
    Call secondMacro

End Sub


'these two macros would be on a public module
Public Sub firstMacro()
    Dim lresult As Long: lresult = Application.Run("SAPExecutePlanningSequence", "PS_1")
        If lresult = 0 Then
                MsgBox "The SapExcecute Planning Sequence failed. All Macros stopped."
                End
        End If

End Sub


Public Sub secondMacro()
    Dim lresult As Long: lresult = Application.Run("SAPExecuteCommand", "PlanDataSave")
        If lresult = 0 Then
                MsgBox "The Save Plan Data operation failed. All Macros stopped."
                End
        End If

End Sub
former_member186338
Active Contributor

To my mind, the location of code in Sheet module have no effect at all. And 2 sub's are also not required. gregor.dieckmann has clearly explained the required changes.

Answers (2)

Answers (2)

Hi Christian,

first one should evaluate IResult and the call PlanDataSave only if IResult = 1. With respect to the messages it might be the design not to send messages directly if functions are called programmatically. It might be annoying if all API calls send messages directly. I would expect that doing things in program includes message handling, i.e. sending messages is up to the program. So you can check the AO API, e.g SAPAddMessage and the function SAPListOfMessages, cf. AO documentation.

Regards,

Gregor

0 Kudos

Hi Guys

Thank you for your answers. I solved it this way:

Sub Button10001_Click() Dim lResult As Long Dim lResult1 As Variant lResult = Application.Run("SAPExecutePlanningSequence", "PS_2") lResult1 = Application.Run("SAPListOfMessages", "ERROR") If IsArray(lResult1) Then If UBound(lResult1) > 0 Then lResult = Application.Run("SAPExecutePlanningSequence", "PS_2") End If Else lResult = Application.Run("SAPExecuteCommand", "PlanDataSave") End If End Sub