Showing posts with label DUOS. Show all posts
Showing posts with label DUOS. Show all posts

21 February, 2009

How to make PO field required for specific customer


This requirement came up last week and after Mariano explained how to do it, I went ahead and did it... for fun. Sick, I know.

I posted an example of using the DUOS a couple of year ago and used that, with very few tweaks, after using Modifier to add a Check Box control to the Customer Maintenance window to store the RequiredPO flag in the DUOS (SY90000) as Mariano suggested. If you have problems converting that example to this scenario let me know and I will e-mail you the code.

After that, all you have to do is add the Sales Transaction Entry Window and the Customer ID and Customer PO Fields on that window to your Visual Basic Project. Open the VB Editor and add this code to the SalesTransactionEntry (Window) to make the Customer PO field required for selected customers:

Option Explicit
Dim Msg, Style, Title, Help, Ctxt, Response, MyString, Default
Dim ItemCollection As DUOSObjects
Dim ItemObject As DUOSObject

Private Sub CustomerID_Changed()

On Error GoTo Proc_Error:

Set ItemCollection = DUOSObjectsGet("Customer")

If CustomerID.Empty = False Then
Set ItemObject = ItemCollection(CustomerID)
If ItemObject.Properties("RequirePO") = "1" Then
CustomerPONumber.Required = True
Else
CustomerPONumber.Required = False
End If
End If

Exit Sub

Proc_Error: MsgBox Error$ & " " & Error, vbOKOnly, "CustomerID_Changed"

End Sub

27 April, 2006

Real Example of using the DUOS

While I am not a fan of using the DUOS with the same methods described in the manual, using ADO with RetrieveGlobals is better and easier in my opinion, I did do so in one instance to store an EDI Account Number for each customer. I added a field to Customer Maintenance and named it "strEDIAccount". Then I added the code below to my VBA project to store the date in and retrieve it from the DUOS (SY90000) table. This isn't much different than the sample code in the manual but it is a real world example. You should be able make some tweaks to this code and use the information in the manual to make this work in your environment. Good luck!

Option Explicit

Dim Msg, Style, Title, Help, Ctxt, Response, MyString, Default
Dim ItemCollection As DUOSObjects
Dim ItemObject As DUOSObject
Dim WanttoDelete As Boolean
Dim ItemDelete As String
Public OkDelete As Boolean

Private Sub Delete_AfterUserChanged()

On Error GoTo Proc_Error:

If WanttoDelete And OkDelete Then
ItemCollection.Remove (ItemDelete)
End If

Exit Sub

Proc_Error: MsgBox Error$ & " " & Error, vbOKOnly, "Delete_AfterUserChanged"

End Sub

Private Sub CustomerID_Changed()

On Error GoTo Proc_Error:

Set ItemCollection = DUOSObjectsGet("Customer")

If CustomerID.Empty = False Then
Set ItemObject = ItemCollection(CustomerID)
strEDIAccount = ItemObject.Properties("EDIAccount")
ItemDelete = CustomerID
OkDelete = True
WanttoDelete = False
End If

Exit Sub

Proc_Error: MsgBox Error$ & " " & Error, vbOKOnly, "CustomerID_Changed"

End Sub

Private Sub Save_BeforeUserChanged(KeepFocus As Boolean, CancelLogic As Boolean)

On Error GoTo Proc_Error:

ItemObject.Properties("EDIAccount") = strEDIAccount

Exit Sub

Proc_Error: MsgBox Error$ & " " & Error, vbOKOnly, "Save_BeforeUserChanged"

End Sub

Private Sub strEDIAccount_AfterUserChanged()

On Error GoTo Proc_Error:

ItemObject.Properties("EDIAccount") = strEDIAccount

Exit Sub

Proc_Error: MsgBox Error$ & " " & Error, vbOKOnly, "strEDIAccount_AfterUserChanged"

End Sub

Private Sub Window_AfterModalDialog(ByVal DlgType As DialogType, PromptString As String, Control1String As String, Control2String As String, Control3String As String, Answer As DialogCtrl)

On Error GoTo Proc_Error:

If PromptString = "Are you sure you want to delete this customer record?" Then
If Answer = dcButton1 Then
WanttoDelete = True
End If
End If

Exit Sub

Proc_Error: MsgBox Error$ & " " & Error, vbOKOnly, "Window_AfterModalDialog"

End Sub