Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why? macro it insert order detail first record only

Status
Not open for further replies.

thocom

Programmer
Jul 22, 2011
2
Hi,
I'm trying a macro to insert an OE order detail in Accpac 6.0
it work! but it insert order detail first record only.

before :
orduniq ordnumber item
3513090 32 001071001

after run macro :
orduniq ordnumber item
3513090 16 001074001
3513090 32 001071001

run macro again :
orduniq ordnumber item
3513090 8 001074001
3513090 16 001074001
3513090 32 001071001

Thank you for your help.

Thocom.
------------------------------------------------------------------

Sub MainSub()


On Error GoTo ACCPACErrorHandler
Dim temp As Boolean
Dim Lin As Integer
Dim mDBLinkCmpRW As AccpacCOMAPI.AccpacDBLink
Set mDBLinkCmpRW = OpenDBLink(DBLINK_COMPANY, DBLINK_FLG_READWRITE)

Dim mDBLinkSysRW As AccpacCOMAPI.AccpacDBLink
Set mDBLinkSysRW = OpenDBLink(DBLINK_SYSTEM, DBLINK_FLG_READWRITE)

Dim OEORD1header As AccpacCOMAPI.AccpacView
Dim OEORD1headerFields As AccpacCOMAPI.AccpacViewFields

Dim OEORD1detail1 As AccpacCOMAPI.AccpacView
Dim OEORD1detail1Fields As AccpacCOMAPI.AccpacViewFields

Dim OEORD1detail3 As AccpacCOMAPI.AccpacView
Dim OEORD1detail3Fields As AccpacCOMAPI.AccpacViewFields

Dim OEORD1detail2 As AccpacCOMAPI.AccpacView
Dim OEORD1detail2Fields As AccpacCOMAPI.AccpacViewFields

Dim OEORD1detail5 As AccpacCOMAPI.AccpacView
Dim OEORD1detail5Fields As AccpacCOMAPI.AccpacViewFields

Dim OEORD1detail6 As AccpacCOMAPI.AccpacView
Dim OEORD1detail6Fields As AccpacCOMAPI.AccpacViewFields

Dim OEORD1detail7 As AccpacCOMAPI.AccpacView
Dim OEORD1detail7Fields As AccpacCOMAPI.AccpacViewFields

Dim OEORD1detail8 As AccpacCOMAPI.AccpacView
Dim OEORD1detail8Fields As AccpacCOMAPI.AccpacViewFields

Dim OEORD1detail9 As AccpacCOMAPI.AccpacView
Dim OEORD1detail9Fields As AccpacCOMAPI.AccpacViewFields

Dim OEORD1detail10 As AccpacCOMAPI.AccpacView
Dim OEORD1detail10Fields As AccpacCOMAPI.AccpacViewFields

Dim OEORD1detail11 As AccpacCOMAPI.AccpacView
Dim OEORD1detail11Fields As AccpacCOMAPI.AccpacViewFields

Dim OEORD1detail12 As AccpacCOMAPI.AccpacView
Dim OEORD1detail12Fields As AccpacCOMAPI.AccpacViewFields

Dim OEORD1detail13 As AccpacCOMAPI.AccpacView
Dim OEORD1detail13Fields As AccpacCOMAPI.AccpacViewFields

mDBLinkCmpRW.OpenView "OE0520", OEORD1header
Set OEORD1headerFields = OEORD1header.Fields

mDBLinkCmpRW.OpenView "OE0500", OEORD1detail1
Set OEORD1detail1Fields = OEORD1detail1.Fields

mDBLinkCmpRW.OpenView "OE0740", OEORD1detail2
Set OEORD1detail2Fields = OEORD1detail2.Fields

mDBLinkCmpRW.OpenView "OE0180", OEORD1detail3
Set OEORD1detail3Fields = OEORD1detail3.Fields

mDBLinkCmpRW.OpenView "OE0526", OEORD1detail5
Set OEORD1detail5Fields = OEORD1detail5.Fields

mDBLinkCmpRW.OpenView "OE0522", OEORD1detail6
Set OEORD1detail6Fields = OEORD1detail6.Fields

mDBLinkCmpRW.OpenView "OE0501", OEORD1detail7
Set OEORD1detail7Fields = OEORD1detail7.Fields

mDBLinkCmpRW.OpenView "OE0502", OEORD1detail8
Set OEORD1detail8Fields = OEORD1detail8.Fields

mDBLinkCmpRW.OpenView "OE0504", OEORD1detail9
Set OEORD1detail9Fields = OEORD1detail9.Fields

mDBLinkCmpRW.OpenView "OE0503", OEORD1detail10
Set OEORD1detail10Fields = OEORD1detail10.Fields

mDBLinkCmpRW.OpenView "OE0507", OEORD1detail11
Set OEORD1detail11Fields = OEORD1detail11.Fields

mDBLinkCmpRW.OpenView "OE0508", OEORD1detail12
Set OEORD1detail12Fields = OEORD1detail12.Fields

mDBLinkCmpRW.OpenView "OE0506", OEORD1detail13
Set OEORD1detail13Fields = OEORD1detail13.Fields

OEORD1header.Compose Array(OEORD1detail1, Nothing, OEORD1detail3, OEORD1detail2, OEORD1detail5, OEORD1detail6)
OEORD1detail1.Compose Array(OEORD1header, OEORD1detail7, OEORD1detail10, OEORD1detail8, OEORD1detail12, OEORD1detail11)
OEORD1detail2.Compose Array(OEORD1header)
OEORD1detail3.Compose Array(OEORD1header, OEORD1detail1)
OEORD1detail5.Compose Array(OEORD1header)
OEORD1detail6.Compose Array(OEORD1header)
OEORD1detail7.Compose Array(OEORD1detail1)
OEORD1detail8.Compose Array(OEORD1detail1, OEORD1detail9, Nothing)
OEORD1detail9.Compose Array(OEORD1detail8)
OEORD1detail10.Compose Array(OEORD1detail1)
OEORD1detail11.Compose Array(OEORD1detail1)
OEORD1detail12.Compose Array(OEORD1detail1)
OEORD1detail13.Compose Array(OEORD1detail8)

OEORD1header.Init
OEORD1detail2.Browse "", 1
OEORD1detail2.Fetch

OEORD1headerFields("ORDNUMBER").Value = "ORD0000000000000000014"
OEORD1header.Order = 1
OEORD1header.Read
temp = OEORD1header.Exists
OEORD1headerFields("PROCESSCMD").PutWithoutVerification ("1") 'Process OIP Command
OEORD1header.Process


OEORD1detail1.RecordClear

temp = OEORD1detail1.Exists
OEORD1detail1.RecordCreate False

temp = OEORD1detail1.Exists
OEORD1detail1Fields("ITEM").Value = "001074001" ' Item
OEORD1detail1Fields("LOCATION").Value = "A03" ' Location
OEORD1detail1Fields("CATEGORY").Value = "SPARE" ' Location
OEORD1detail1Fields("QTYORDERED").Value = "1" ' Quantity Ordered
'OEORD1detail1Fields("PRIUNTPRC").Value = "9000000.000000" ' Pricing Unit Price
OEORD1detail1Fields("TCLASS1").Value = "1"

OEORD1detail1Fields("TAUTH5").Value = "VAT7G"

OEORD1detail1.Process
OEORD1detail1.Insert
OEORD1detail1.Read
'MsgBox (OEORD1detail1Fields("LINENUM").Value)
'OEORD1detail1Fields("LINENUM").PutWithoutVerification ("64")
'temp = OEORD1detail1.Exists
'OEORD1detail1.Update
'OEORD1detail1.Init
OEORD1headerFields("GOFCALCTAX").PutWithoutVerification ("1") ' Perform Forced Tax Calculation
'OEORD1header.Process
OEORD1headerFields("PROCESSCMD").PutWithoutVerification ("1") 'Process OIP Command
OEORD1header.Process

'OEORD1header.Process
OEORD1header.Update

Exit Sub
ACCPACErrorHandler:
Dim lCount As Long
Dim lIndex As Long

If Errors Is Nothing Then
MsgBox Err.Description
Else
lCount = Errors.Count

If lCount = 0 Then
MsgBox Err.Description
Else
For lIndex = 0 To lCount - 1
MsgBox Errors.Item(lIndex)
Next
Errors.Clear
End If
Resume Next
End If



End Sub
 
Your code is messy, you need to get rid of all the "temp=" lines. And, your snippet also doesn't show where the problem is.
 
Here is some sample code showing how to add OE detail lines and maintain the order in which they were imported. If you simple add the lines without setting the keys explicity then the records will appear in the document in reverse order.


You might want to call DetailFile.GoBottom to get the initial value for LineNo.

Code:
LineNo = -1
    While Not (DetailFile.EOF)
        OEORD1detail1.RecordClear
        OEORD1detail1.Fields("LINENUM").PutWithoutVerification (LineNo)
        OEORD1detail1.RecordGenerate False
        OEORD1detail1.Fields("ITEM").Value = DetailFile.Fields("ITEM").Value
        OEORD1detail1.Fields("PROCESSCMD").PutWithoutVerification ("1")
        If IsItemABOM(DetailFile.Fields("ITEM").Value) Then
            OEORD1detail1.Fields("DDTLNO").Value = "1"
        End If
        OEORD1detail1.Process
        OEORD1detail1.Fields("QTYORDERED").Value = _
              DetailFile.Fields("QTYORDERED").Value
        OEORD1detail1.Insert
        LineNo = OEORD1detail1.Fields("LINENUM").Value
        DetailFile.MoveNext
    Wend
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top