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!

Accpac Com Api OE order create from Macro

Status
Not open for further replies.

AccPal

Programmer
Jun 13, 2009
8
Hi All

Im fairly new to the Accpac Com API ive recorded a macro

and inserted the code on to a button control in VB 2008

what will i need to do from here a connection string ETC

ive referenced Com api and it now is happy with AccpacCOMAPI
but its not happy with OpenDBLink(DBLINK_COMPANY, DBLINK_FLG_READWRITE) it says its not declared

macro that was recorded


' Sage Accpac Macro file: D:\A4W\oe.AVB
' Recorded at: Sat Jun 13 11:58:46 2009
'

On Error GoTo ACCPACErrorHandler

' TODO: To increase efficiency, comment out any unused DB links.
Dim mDBLinkCmpRW As AccpacCOMAPI.AccpacDBLink
mDBLinkCmpRW = OpenDBLink(DBLINK_COMPANY, DBLINK_FLG_READWRITE)

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

Dim temp As Boolean
Dim OEORD1header As AccpacCOMAPI.AccpacView
Dim OEORD1headerFields As AccpacCOMAPI.AccpacViewFields
mDBLinkCmpRW.OpenView("OE0520", OEORD1header)
OEORD1headerFields = OEORD1header.Fields

Dim OEORD1detail1 As AccpacCOMAPI.AccpacView
Dim OEORD1detail1Fields As AccpacCOMAPI.AccpacViewFields
mDBLinkCmpRW.OpenView("OE0500", OEORD1detail1)
OEORD1detail1Fields = OEORD1detail1.Fields

Dim OEORD1detail2 As AccpacCOMAPI.AccpacView
Dim OEORD1detail2Fields As AccpacCOMAPI.AccpacViewFields
mDBLinkCmpRW.OpenView("OE0740", OEORD1detail2)
OEORD1detail2Fields = OEORD1detail2.Fields

Dim OEORD1detail3 As AccpacCOMAPI.AccpacView
Dim OEORD1detail3Fields As AccpacCOMAPI.AccpacViewFields
mDBLinkCmpRW.OpenView("OE0180", OEORD1detail3)
OEORD1detail3Fields = OEORD1detail3.Fields

Dim OEORD1detail4 As AccpacCOMAPI.AccpacView
Dim OEORD1detail4Fields As AccpacCOMAPI.AccpacViewFields
mDBLinkCmpRW.OpenView("OE0680", OEORD1detail4)
OEORD1detail4Fields = OEORD1detail4.Fields

Dim OEORD1detail5 As AccpacCOMAPI.AccpacView
Dim OEORD1detail5Fields As AccpacCOMAPI.AccpacViewFields
mDBLinkCmpRW.OpenView("OE0526", OEORD1detail5)
OEORD1detail5Fields = OEORD1detail5.Fields

Dim OEORD1detail6 As AccpacCOMAPI.AccpacView
Dim OEORD1detail6Fields As AccpacCOMAPI.AccpacViewFields
mDBLinkCmpRW.OpenView("OE0522", OEORD1detail6)
OEORD1detail6Fields = OEORD1detail6.Fields

Dim OEORD1detail7 As AccpacCOMAPI.AccpacView
Dim OEORD1detail7Fields As AccpacCOMAPI.AccpacViewFields
mDBLinkCmpRW.OpenView("OE0501", OEORD1detail7)
OEORD1detail7Fields = OEORD1detail7.Fields

Dim OEORD1detail8 As AccpacCOMAPI.AccpacView
Dim OEORD1detail8Fields As AccpacCOMAPI.AccpacViewFields
mDBLinkCmpRW.OpenView("OE0502", OEORD1detail8)
OEORD1detail8Fields = OEORD1detail8.Fields

Dim OEORD1detail9 As AccpacCOMAPI.AccpacView
Dim OEORD1detail9Fields As AccpacCOMAPI.AccpacViewFields
mDBLinkCmpRW.OpenView("OE0504", OEORD1detail9)
OEORD1detail9Fields = OEORD1detail9.Fields

Dim OEORD1detail10 As AccpacCOMAPI.AccpacView
Dim OEORD1detail10Fields As AccpacCOMAPI.AccpacViewFields
mDBLinkCmpRW.OpenView("OE0503", OEORD1detail10)
OEORD1detail10Fields = OEORD1detail10.Fields

OEORD1header.Compose(Array(OEORD1detail1, OEORD1detail4, OEORD1detail3, OEORD1detail2, OEORD1detail5, OEORD1detail6))

OEORD1detail1.Compose(Array(OEORD1header, OEORD1detail7, OEORD1detail10, OEORD1detail8))

OEORD1detail2.Compose(Array(OEORD1header))

OEORD1detail3.Compose(Array(OEORD1header, OEORD1detail1))

OEORD1detail4.Compose(Array(OEORD1header, OEORD1detail1))

OEORD1detail5.Compose(Array(OEORD1header))

OEORD1detail6.Compose(Array(OEORD1header))

OEORD1detail7.Compose(Array(OEORD1detail1))

OEORD1detail8.Compose(Array(OEORD1detail1, OEORD1detail9))

OEORD1detail9.Compose(Array(OEORD1detail8))

OEORD1detail10.Compose(Array(OEORD1detail1))



OEORD1headerFields("DRIVENBYUI").Value = "1" ' Driven by UI

OEORD1detail1Fields("DRIVENBYUI").Value = "1" ' Driven by UI
OEORD1header.Cancel()
OEORD1header.Cancel()
temp = OEORD1header.Exists
OEORD1header.Init()
OEORD1detail2.Browse("", 1)
OEORD1detail2.Fetch()
OEORD1headerFields("CUSTOMER").Value = "AIR001" ' Customer Number
OEORD1detail2.Browse("", 1)

OEORD1detail2Fields("PAYMENT").PutWithoutVerification("-32767") ' Payment Number

OEORD1detail2.Browse("", -1)
OEORD1detail2.Fetch()
OEORD1headerFields("PROCESSCMD").PutWithoutVerification("1") ' Process OIP Command
OEORD1header.Process()

OEORD1headerFields("CUSTOMER").Value = "BAK001" ' Customer Number
OEORD1detail2.Browse("", 1)

OEORD1detail2Fields("PAYMENT").PutWithoutVerification("-32767") ' Payment Number

OEORD1detail2.Browse("", -1)
OEORD1detail2.Fetch()
OEORD1headerFields("PROCESSCMD").PutWithoutVerification("1") ' Process OIP Command
OEORD1header.Process()

OEORD1headerFields("TEMPLATE").Value = "DEF" ' Template Code

OEORD1detail2.Browse("", 1)

OEORD1detail2Fields("PAYMENT").PutWithoutVerification("-32767") ' Payment Number

OEORD1detail2.Browse("", -1)
OEORD1detail2.Fetch()
temp = OEORD1header.Exists

OEORD1headerFields("GOCALCTAX").PutWithoutVerification("1") ' Perform Tax Calculation

OEORD1header.Process()

OEORD1headerFields("PONUMBER").Value = "P012345" ' Purchase Order Number
temp = OEORD1detail1.Exists
OEORD1detail1.RecordClear()
temp = OEORD1detail1.Exists
OEORD1detail1.RecordCreate(0)

OEORD1detail1Fields("ITEM").Value = "1000" ' Item
OEORD1detail1Fields("PROCESSCMD").PutWithoutVerification("1") ' Process Command

OEORD1detail1.Process()

OEORD1detail1Fields("DESC").Value = "Consulting Accpac123" ' Description
OEORD1detail1Fields("QTYORDERED").Value = "1.0000" ' Quantity Ordered

OEORD1detail1.Insert()

OEORD1detail1Fields("LINENUM").PutWithoutVerification("-1") ' Line Number

OEORD1detail1.Read()
temp = OEORD1detail1.Exists
OEORD1detail1.RecordCreate(0)

OEORD1detail1Fields("LINENUM").PutWithoutVerification("-1") ' Line Number

OEORD1detail1.Read()
temp = OEORD1detail1.Exists
OEORD1detail1.RecordCreate(0)

OEORD1detail1Fields("ITEM").Value = "1100" ' Item
OEORD1detail1Fields("PROCESSCMD").PutWithoutVerification("1") ' Process Command

OEORD1detail1.Process()

OEORD1detail1Fields("QTYORDERED").Value = "60.0000" ' Quantity Ordered

OEORD1detail1.Insert()

OEORD1detail1Fields("LINENUM").PutWithoutVerification("-3") ' Line Number

OEORD1detail1.Read()
OEORD1headerFields("OECOMMAND").Value = "4" ' Process O/E Command
OEORD1header.Process()
OEORD1header.Insert()
OEORD1header.Order = 1
OEORD1header.Read()
OEORD1header.Order = 0
OEORD1detail1Fields("LINENUM").PutWithoutVerification("-32767") ' Line Number
OEORD1detail1.Browse("", 1)
OEORD1detail1.Fetch()
OEORD1detail8Fields("PRNCOMPNUM").PutWithoutVerification("-2147483647") ' Parent Component Number

OEORD1detail8Fields("COMPNUM").PutWithoutVerification("-2147483647") ' Component Number

OEORD1detail8.Browse("", 1)
OEORD1detail8.Fetch()
OEORD1detail4Fields("UNIQUIFIER").PutWithoutVerification("-32767") ' Uniquifier
OEORD1detail4.Browse("", 1)
OEORD1detail4.Fetch()
OEORD1detail3Fields("UNIQUIFIER").PutWithoutVerification("-32767") ' Uniquifier
OEORD1detail3.Browse("", 1)
OEORD1detail3.Fetch()
OEORD1detail2Fields("PAYMENT").PutWithoutVerification("-32767") ' Payment Number
OEORD1detail2.Browse("", -1)
OEORD1detail2.Fetch()

OEORD1detail2Fields("PAYMENT").PutWithoutVerification("-3") ' Payment Number
OEORD1detail2.Browse("", 1)

OEORD1detail2Fields("PAYMENT").PutWithoutVerification("-32767") ' Payment Number

OEORD1detail2.Browse("", -1)
OEORD1detail2.Fetch()
temp = OEORD1header.Exists

OEORD1headerFields("GOSHIPALL").Value = "1" ' Perform Ship All

OEORD1header.Process()

OEORD1headerFields("OECOMMAND").Value = "4" ' Process O/E Command

OEORD1header.Process()
temp = OEORD1header.Exists
OEORD1header.Update()
OEORD1header.Order = 1
OEORD1header.Read()
OEORD1header.Order = 0
OEORD1detail1Fields("LINENUM").PutWithoutVerification("-32767") ' Line Number
OEORD1detail1.Browse("", 1)
OEORD1detail1.Fetch()
OEORD1detail8Fields("PRNCOMPNUM").PutWithoutVerification("-2147483647") ' Parent Component Number

OEORD1detail8Fields("COMPNUM").PutWithoutVerification("-2147483647") ' Component Number

OEORD1detail8.Browse("", 1)
OEORD1detail8.Fetch()
OEORD1detail4Fields("UNIQUIFIER").PutWithoutVerification("-32767") ' Uniquifier
OEORD1detail4.Browse("", 1)
OEORD1detail4.Fetch()
OEORD1detail3Fields("UNIQUIFIER").PutWithoutVerification("-32767") ' Uniquifier
OEORD1detail3.Browse("", 1)
OEORD1detail3.Fetch()
OEORD1detail2Fields("PAYMENT").PutWithoutVerification("-32767") ' Payment Number
OEORD1detail2.Browse("", -1)
OEORD1detail2.Fetch()
OEORD1detail2.Browse("", 1)

OEORD1detail2Fields("PAYMENT").PutWithoutVerification("-32767") ' Payment Number

OEORD1detail2.Browse("", -1)
OEORD1detail2.Fetch()
temp = OEORD1header.Exists
OEORD1header.Order = 1
OEORD1header.Read()
OEORD1header.Order = 0
OEORD1detail1Fields("LINENUM").PutWithoutVerification("-32767") ' Line Number
OEORD1detail1.Browse("", 1)
OEORD1detail1.Fetch()
OEORD1detail8Fields("PRNCOMPNUM").PutWithoutVerification("-2147483647") ' Parent Component Number

OEORD1detail8Fields("COMPNUM").PutWithoutVerification("-2147483647") ' Component Number

OEORD1detail8.Browse("", 1)
OEORD1detail8.Fetch()
OEORD1detail4Fields("UNIQUIFIER").PutWithoutVerification("-32767") ' Uniquifier
OEORD1detail4.Browse("", 1)
OEORD1detail4.Fetch()
OEORD1detail3Fields("UNIQUIFIER").PutWithoutVerification("-32767") ' Uniquifier
OEORD1detail3.Browse("", 1)
OEORD1detail3.Fetch()
OEORD1detail2Fields("PAYMENT").PutWithoutVerification("-32767") ' Payment Number
OEORD1detail2.Browse("", -1)
OEORD1detail2.Fetch()
OEORD1detail2.Browse("", 1)

OEORD1detail2Fields("PAYMENT").PutWithoutVerification("-32767") ' Payment Number

OEORD1detail2.Browse("", -1)
OEORD1detail2.Fetch()
temp = OEORD1header.Exists


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

 
You need to declare an Accpac session in VB and then .Init and .Open the session, there are some examples if you search.
 
Thank you for the quick response im still struggling though
this is the connection

Dim Session As New AccpacCOMAPI.AccpacSession
Dim DBLink As AccpacCOMAPI.AccpacDBLink

Session.Init("", "AS", "AS1000", "55A")
Session.Open("ADMIN", "ADMIN", "TSTDAT", Date.Today, 0, "")

Dim mDBLinkCmpRW As AccpacCOMAPI.AccpacDBLink
mDBLinkCmpRW = Session.OpenDBLink(DBLINK_COMPANY, DBLINK_FLG_READWRITE)


i get errors in VB 2008 as follows
Error 1 Name 'DBLINK_COMPANY' is not declared.
Error 2 Name 'DBLINK_FLG_READWRITE' is not declared.

is there a way i should be using it or am i doing something stupid

your help will be really great
 
hi there and how can i handle the Array

OEORD1header.Compose(Array(OEORD1detail1, OEORD1detail4, OEORD1detail3, OEORD1detail2, OEORD1detail5, OEORD1detail6))


i get error
Error 1 'Array' is a type and cannot be used as an expression.

sorry fo being a pain
 
The syntax in VB 2008 is totally different, you will have to figure it out.
Is there a compelling reason to use VB2008? Why not just run in VBA?
 
thanks wrote app in 2008 want to bring Jobs into Oe Orders

ill have to re-write app in vb6 to understand how it works first
 
Here's an example of creating the composition in .net:
Code:
        'ICITEM.Compose(Nothing, Nothing, ICITMV, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing)
        Dim icViews(8) As AccpacCOMAPI.AccpacView
        icViews(0) = Nothing
        icViews(1) = Nothing
        icViews(2) = ICITMV
        For i = 3 To 8
            icViews(i) = Nothing
        Next i
        ICITEM.Compose(icViews)
 
thanks ill play around with that
 
thank you for the response
Could you please send me a full example of code in .net

from connection to creation of something
ie

change customer email address or something

that will help me alot i can play with the code and see how it all works
 
Other than creating the array of views to handle the composition the code is very similar to what appears in a VBA macro.
Code:
[b]Private[/b] [b]Function[/b] OpenAndComposeViews() [b]As[/b] [b]Boolean[/b]
        OpenAndComposeViews = True
        [b]If[/b] bOpenAndComposedViews [b]Then[/b] [b]Exit[/b] [b]Function[/b]

        mDBLinkCmpRW = Session.OpenDBLink(1, 0)
        mDBLinkCmpRW.OpenView([navy]"GL0003"[/navy], GLF)
        mDBLinkCmpRW.OpenView([navy]"CS0001"[/navy], CSCOM)
        mDBLinkCmpRW.OpenView([navy]"GL0001"[/navy], GLAMF)

        CSCOM.Browse([navy]""[/navy], True)
        CSCOM.Fetch()
        FunctionalCurrency = CSCOM.Fields.FieldByName([navy]"HOMECUR"[/navy]).Value
        CSCOM.[b]Close[/b]()

        bOpenAndComposedViews = True
    [b]End[/b] [b]Function[/b]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top