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.
KateHulitAsked:
Who is Participating?
 
Abdulmalek_HamshoCommented:
But you're referring to fields in SalesItemDetailEntry while this window is closed.

You need to open The SalesItemDetailEntry window right after this statement:

If SOPRecord.EOF = False Then


You can make it hidden if you want.
0
 
Abdulmalek_HamshoCommented:
Could you add breakpoints and tell us where (on which line?) does it show this error?
0
 
KateHulitAuthor Commented:
I stepped through it already and the error pops up as soon as you get to

SOPRecord!WrapStrap = SalesItemDetailEntry.WrapStrap
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Abdulmalek_HamshoCommented:
In which event and which window does this code run?
0
 
KateHulitAuthor Commented:
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.
0
 
Abdulmalek_HamshoCommented:
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.
0
 
KateHulitAuthor Commented:
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
0
 
KateHulitAuthor Commented:
found the problem.  Missed  a section of code in the end.
0
 
Abdulmalek_HamshoCommented:
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?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.