Baanboard.com

Baanboard.com (http://www.baanboard.com/baanboard/index.php)
-   AFS/DDC/OLE: Function servers (http://www.baanboard.com/baanboard/forumdisplay.php?f=59)
-   -   Getting item description through Baan OLE automation (http://www.baanboard.com/baanboard/showthread.php?t=70381)

VishalMistry 30th August 2017 14:32

Getting item description through Baan OLE automation
 
Hi all,

I have little or no experience related to Baan OLE automation, but i want to explore it. I want to perform a simple task as shown below:

pass an item code using stpapi.put.field
search the item record using stpapi.find
get the value of item description using stpapi.get.field

For this I have written attached code in Excel VBA. I have debugged code in VBA and it gives an error message indicating invalid number of arguments whereas I am passing three argument (sessioncode,tablefield,getfield) to stpapi.get.field function.

getfield is excel vba variable.

BaanObj.ParseExecFunction "ottstpapihand", "stpapi.get.field(" & Chr(34) & SessionName & Chr(34) & "," & Chr(34) & "tiitm001.dsca" & Chr(34) & "," & getfield & ")"

Can anybody guide me how to write the above statement correctly in VBA so that I will get item description in getfield variable ?

Thanks,
Vishal

VishalMistry 30th August 2017 15:03

I could get rid of the error with below statement:

BaanObj.ParseExecFunction "ottstpapihand", "stpapi.get.field(" & Chr(34) & SessionName & Chr(34) & "," & Chr(34) & "tiitm001.dsca" & Chr(34) & ",itemdesc" & ")"

But still while displaying value of itemdesc, the value remains empty.

Any clue what could be wrong here ?

NOTE : I changed the name of variable from getfield to itemdesc

Vishal

mark_h 30th August 2017 20:20

I only have this that I tested a couple of times - notice the baan function call and how I had to use mid$ to get a description.

Code:

datarec$ = "datarec"
retVal2$ = "retval"
retval = Space(128)
getfield = Space(30)
Set BaanObj = CreateObject("Baan4.Application.701")

BaanObj.Timeout = 10
'AREAS TEST RETURN VAL...
'put area 'AZ, find , get desc
'put area
SessionName$ = "tcmcs0145m000"
FieldName$ = "tcmcs045.creg"
FieldValue$ = "105"
BaanObj.ParseExecFunction "ottstpapihand", "stpapi.put.field(" & Chr(34) & SessionName$ & Chr(34) & "," & Chr(34) & FieldName$ & Chr(34) & "," & Chr(34) & FieldValue$ & Chr(34) & ")"

BaanObj.ParseExecFunction "ottstpapihand", "stpapi.find(" & Chr(34) & SessionName$ & Chr(34) & ")"

errstr = BaanObj.Error
'get desc
SessionName$ = "tcmcs0145m000"
FieldName$ = "tcmcs045.dsca"

BaanObj.ParseExecFunction "ottstpapihand", "stpapi.get.field(" & Chr(34) & SessionName$ & Chr(34) & "," & Chr(34) & FieldName$ & Chr(34) & "," & Chr(34) & getfield & Chr(34) & ")"
tempstr$ = BaanObj.FunctionCall

descr = Mid(tempstr$, 50, 32)

longVar = BaanObj.ReturnValue

errstr = BaanObj.Error
MsgBox (descr)

BaanObj.ParseExecFunction "ottstpapihand", "stpapi.end.session(" & Chr(34) & SessionName$ & Chr(34) & "," & Chr(34) & errmessage1 & Chr(34) & ")"


VishalMistry 31st August 2017 11:25

Hello Mark,

Your code is working. One strange thing (and it has nothing to do with your code) is if I am already connected to Baan and run my macro then I get ole automation error. For the code to work, I have to logout of Baan, then only I can run the Excel code.

Thanks for your help.
Vishal

mark_h 31st August 2017 14:54

Yes - I recall that happening also. I believe that was one of the reasons I never went this direction because it was very slow in our environment. I never really played with this a lot.


All times are GMT +2. The time now is 01:40.


vB.Sponsors
©2001-2017 - Baanboard.com - Baanforums.com