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

No comments: