planetbluau
Programmer
Can anyone help with the following code? I am trying to return the current pricing for a customer (to allow for sale pricing etc). The code below does not return the correct values. I have put a few MsgBox's to show values. When the code runs, the BILNAME is always correct. (In SAMINC 1200 will return Ronald Black and 1100 Bargain Mart - San Diago) However, the PRICELIST is WRONG (seems to just return the first it encounters) and so too is the price.
When I run the same VBA code in a macro, it's correct. Can you see where the code maybe wrong?
(The project needs to be done in vb.NET so using the MACRO is not an option.)
MY CODE
When I run the same VBA code in a macro, it's correct. Can you see where the code maybe wrong?
(The project needs to be done in vb.NET so using the MACRO is not an option.)
MY CODE
Code:
Public Sub CheckPrice()
'This checks the PriceToCheck value = the Proper price for the customer and returns true if equals
Dim mSession As New AccpacCOMAPI.AccpacSession
mSession = CreateObject("Accpac.Session")
mSession.Init("", "XY", "XY1000", "61A")
mSession.Open("ADMIN", "ADMIN", "SAMLTD", Now.Date, 0, "")
Dim mDBLinkCmpRW As AccpacCOMAPI.AccpacDBLink
mDBLinkCmpRW = mSession.OpenDBLink(1, 0)
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 OEORD1detail9 As AccpacCOMAPI.AccpacView
Dim OEORD1detail9Fields As AccpacCOMAPI.AccpacViewFields
mDBLinkCmpRW.OpenView("OE0502", OEORD1detail9)
OEORD1detail9Fields = OEORD1detail9.Fields
'vb.net code to compose arrays
Dim icViews(4) As AccpacCOMAPI.AccpacView
icViews(0) = OEORD1detail1
icViews(1) = Nothing
icViews(2) = Nothing
icViews(3) = OEORD1detail2
OEORD1header.Compose(icViews)
ReDim icViews(4)
icViews(0) = OEORD1header
icViews(1) = Nothing
icViews(2) = Nothing
icViews(3) = OEORD1detail9
OEORD1detail1.Compose(icViews)
OEORD1detail2.Compose(OEORD1header)
OEORD1detail9.Compose(OEORD1detail1)
'enter customer and item
[COLOR=#204A87][b]OEORD1headerFields.FieldByName("CUSTOMER").Value = "1100" ' Set Customer Number
MsgBox(OEORD1headerFields.FieldByName("BILNAME").Value) ' Returns Bilname correctly
MsgBox(OEORD1headerFields.FieldByName("PRICELIST").Value) ' Does not return PRICELIST correctly
OEORD1detail1Fields.FieldByName("ITEM").Value = "A1-105/0" ' Set Item
MsgBox(OEORD1detail1Fields.FieldByName("UNITPRICE").Value) ' Return Value - is incorrect[/b][/color]
mDBLinkCmpRW.Close()
mSession.Close()
Exit Sub