Link to home
Start Free TrialLog in
Avatar of KateHulit
KateHulit

asked on

VBA Automation Error

This is my code
If Answer = dcButton1 Then

            Set SOPConnect = New ADODB.Connection
            Set SOPRecord = New ADODB.Recordset

            Set SOPConnect = UserInfoGet.CreateADOConnection
            SOPConnect.DefaultDatabase = UserInfoGet.IntercompanyID

                If SalesTransactionEntry.OriginalNumber <> "" Then DocumentNumber = SalesTransactionEntry.OriginalNumber Else DocumentNumber = SalesTransactionEntry.DocumentNo
           
                    cmd = "Delete from SOP10200Container where SOPNumbe = '" & DocumentNumber & "' and Lnitmseq = '" & CDbl(SalesTransactionEntryDetail.LineItemSequence) & "'"
                    SOPRecord.Open cmd, SOPConnect, adOpenKeyset, adLockOptimistic
               
                End If
               
        If Answer = dcButton2 Then
       
            Set SOPConnect = New ADODB.Connection
            Set SOPRecord = New ADODB.Recordset
   
            Set SOPConnect = UserInfoGet.CreateADOConnection
            SOPConnect.DefaultDatabase = UserInfoGet.IntercompanyID
           
            If SalesTransactionEntry.OriginalNumber <> "" Then DocumentNumber = SalesTransactionEntry.OriginalNumber Else DocumentNumber = SalesTransactionEntry.DocumentNo
            cmd = "Select * from SOP10200Container where Sopnumbe='" & DocumentNumber & "'and Lnitmseq = '" & CDbl(SalesTransactionEntryDetail.LineItemSequence) & "'"
   
            SOPRecord.Open cmd, SOPConnect, adOpenKeyset, adLockOptimistic
           
                If SOPRecord.EOF = False Then
           
                    SOPRecord!WrapStrap = SalesItemDetailEntry.WrapStrap
                    SOPRecord!Packaging = SalesItemDetailEntry.Packaging
                    SOPRecord!SealNo = SalesItemDetailEntry.Seal
                    SOPRecord!BalesInContainer = SalesItemDetailEntry.ContainerNoBales
                    SOPRecord!ContainerWeight = SalesItemDetailEntry.ContainerWeight
                    SOPRecord!ContainerMaxWeight = SalesItemDetailEntry.ContainerMaxWeight
                    SOPRecord!LotNumber = SalesItemDetailEntry.LotNumber
                    If SalesItemDetailEntry.ContainerNo = "" Then SOPRecord!ContainerNo = "NA" Else SOPRecord!ContainerNo = SalesItemDetailEntry.ContainerNo
                    SOPRecord!Split = SalesItemDetailEntry.Split
                    SOPRecord.Update
           
                End If

I entered the dcbutton2 code because when we use the delete line button on sales transaction entry in great plains and select cancel, it deletes all additional information on the item detail window.  It works just fine but I get this error and do not know what it is.

Run-time error '0'

Automation error
The operation completed successfully.

Sure would like to get rid of this error.
Avatar of Abdulmalek_Hamsho
Abdulmalek_Hamsho
Flag of United Arab Emirates image

Could you add breakpoints and tell us where (on which line?) does it show this error?
Avatar of KateHulit
KateHulit

ASKER

I stepped through it already and the error pops up as soon as you get to

SOPRecord!WrapStrap = SalesItemDetailEntry.WrapStrap
In which event and which window does this code run?
Private Sub Window_AfterModalDialog(ByVal DlgType As DialogType, PromptString As String, Control1String As String, Control2String As String, Control3String As String, Answer As DialogCtrl)


In sales transaction entry window.  I need to code the cancel button for when they use the insert and delete icons on the line item window.
ASKER CERTIFIED SOLUTION
Avatar of Abdulmalek_Hamsho
Abdulmalek_Hamsho
Flag of United Arab Emirates image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Remember to close it at the end of your code, because if you opened it and hide it, you want be able to close it from the interface.
I have to put this on hold for a minute until I get my other sql question figured out.  I will then be back.

Thanks
found the problem.  Missed  a section of code in the end.
So you were having two problems, the first is you're referring to an object in a closed window (SalesItemDetailEntry), and the second one you missed a section.

Is it working now?