' Created by Mariano Gomez, MVP
' Code is provided "as is". No warranties express or implied
Option Explicit
Dim ParamCollection As DUOSObjects
Dim ParamObject As DUOSObject
Private Sub ActionButton_BeforeUserChanged(KeepFocus As Boolean, CancelLogic As Boolean)
' Dim CompilerApp As New Dynamics.Application
Dim CompilerApp As Object
Dim CompilerMessage As String
Dim CompilerError As Integer
Dim CompilerCommand As String
Dim ActionValue As Integer
ActionValue = 0
' Initialize DUOS
Set ParamCollection = DUOSObjectsGet("Param." & UCase(UserInfoGet.UserID))
Set ParamObject = ParamCollection.Item("SOPEntryAction")
ParamObject.Properties("ActionValue") = Str(ActionValue)
CompilerCommand = CompilerCommand & "clear table SY_User_Object_Store; " & vbCrLf
CompilerCommand = CompilerCommand & "'ObjectType' of table SY_User_Object_Store = """ & "Param." & UCase(UserInfoGet.UserID) & """; " & vbCrLf
CompilerCommand = CompilerCommand & "'ObjectID' of table SY_User_Object_Store = """ & "SOPEntryAction" & """; " & vbCrLf
CompilerCommand = CompilerCommand & "'PropertyName' of table SY_User_Object_Store = """ & "ActionValue" & """; " & vbCrLf
CompilerCommand = CompilerCommand & "change table SY_User_Object_Store; " & vbCrLf
CompilerCommand = CompilerCommand & "'PropertyValue' of table SY_User_Object_Store = str(itemdata('Action Button' of window SOP_Entry of form SOP_Entry, 'Action Button' of window SOP_Entry of form SOP_Entry)); " & vbCrLf
CompilerCommand = CompilerCommand & "save table SY_User_Object_Store; " & vbCrLf
CompilerCommand = CompilerCommand & "check error; " & vbCrLf
' Shows you the sanScript code to be executed -- comment out for your project
'MsgBox CompilerCommand
' Execute SanScript
Set CompilerApp = CreateObject("Dynamics.Application")
CompilerError = CompilerApp.ExecuteSanscript(CompilerCommand, CompilerMessage)
If CompilerError <> 0 Then
MsgBox CompilerMessage
Else
' Retrieve return values from DUOS
Set ParamCollection = DUOSObjectsGet("Param." & UCase(UserInfoGet.UserID))
Set ParamObject = ParamCollection.Item("SOPEntryAction")
ActionValue = Val(ParamObject.Properties("ActionValue"))
ParamCollection.Remove ("SOPEntryAction")
End If
Set CompilerApp = Nothing
' The Actions button will return the following values regardless of document
' type - these values are stored in the ActionValue variable
' 1 - ACTION_POST
' 2 - ACTION_TRANSFER
' 3 - ACTION_PURCHASE
' 4 - ACTION_CONFIRMPICK
' 5 - ACTION_CONFIRMPACK
' 6 - ACTION_CONFIRMSHIP
' 7 - ACTION_COPY
' 8 - ACTION_DELETE
' 9 - ACTION_VOID
If ActionValue = 8 Then
CancelLogic = True
MsgBox ("Delete Not Allowed")
End If
End Sub