rduncan10
8th August 2007, 19:26
Hi,
I'm learning how to do AFS from an Excel VBA macro, using the Baan samples, and many of the posts in this form, especially http://www.baanboard.com/baanboard/showthread.php?t=13049&highlight=functioncall and http://www.baanboard.com/baanboard/showthread.php?s=&threadid=774&highlight=excel.
As I understand it the functioncall property of the Baan OLE object should return the results of the Baan function. But when I run it, it returns just the statement I passed to the function. I think I'm missing something.
For example, I'm writing some code to add a line to a sales order. If the Baan DLL function is successful, it should return the new position number. This works if there is valid data in Excel. But now I'm trying to trap various errors. For example, if the item number is wrong, it should return the "item not found" error.
Here is my code:
Baan DLL Function:
function extern domain tcmcs.st30 add_line( domain tcorno i.orno,
domain tcitem i.item,
long i.oqua,
string err.msg(100))
{long ret
string rstr(30), value(10)
domain tcqsl1 o.qty
o.qty = i.oqua
stpapi.put.field("tdsls4101m000", "tdsls040.orno", str$(i.orno))
stpapi.find("tdsls4101m000")
stpapi.handle.subproc("tdsls4101m000", "tdsls4102s000", "add")
stpapi.continue.process("tdsls4101m000", err.msg)
stpapi.put.field("tdsls4102s000", "tdsls041.item", i.item)
stpapi.put.field("tdsls4102s000", "tdsls041.oqua", str$(o.qty))
ret = stpapi.insert("tdsls4102s000", 1, err.msg)
if ret = 0 then
rstr = err.msg
stpapi.recover("tdsls4102s000", err.msg)
else
stpapi.get.field("tdsls4102s000", "tdsls041.pono", value)
rstr=value
endif
stpapi.end.session("tdsls4102s000")
stpapi.end.session("tdsls4101m000")
return(rstr)
}
Here is the VBA code that calls the function (somewhat condensed for this example):
strDLL = "omySalesFunction"
lngSO = 123456
strItem = "BadItemCode"
lngQty = 1
strFunc = "add_line(" & lngSO & _
", " & Chr(34) & strItem & Chr(34) & ", " & _
lngQty & ", " & Chr(34) & Space(100) & Chr(34) & ")"
Set objBaan = CreateObject("Baan4.Application")
objBaan.ParseExecFunction strDLL, strFunc
varRetVal = objBaan.returnvalue
varErrVal = objBaan.Error
debug.print objBaan.functioncall
Sorry, this code is a bit rough still, and shows some trial and error.
When I run this, the functioncall is the same as the string I sent in ParseExecFunction, ie "add_line(123456, "BadItemCode", 1, "[100 spaces]").
I thought from all the examples I've seen that the last position of the functioncall would have contained the error code, instead of just 100 spaces, but it does not change.
The Baan DLL function right now returns "Item Not Found" in this case, instead of the position number. I want my VBA code to recongnize that it got an error back instead valid data. I know that I could just test for a long here, but I am trying to write generic code (a VBA class module actually) that will work in a variety of situations. The "Item Not Found" error does not generate anything reconginzed by objBaan.Error.
Is what I'm trying to do possible? Am I missing something?
Thanks,
Rob
I'm learning how to do AFS from an Excel VBA macro, using the Baan samples, and many of the posts in this form, especially http://www.baanboard.com/baanboard/showthread.php?t=13049&highlight=functioncall and http://www.baanboard.com/baanboard/showthread.php?s=&threadid=774&highlight=excel.
As I understand it the functioncall property of the Baan OLE object should return the results of the Baan function. But when I run it, it returns just the statement I passed to the function. I think I'm missing something.
For example, I'm writing some code to add a line to a sales order. If the Baan DLL function is successful, it should return the new position number. This works if there is valid data in Excel. But now I'm trying to trap various errors. For example, if the item number is wrong, it should return the "item not found" error.
Here is my code:
Baan DLL Function:
function extern domain tcmcs.st30 add_line( domain tcorno i.orno,
domain tcitem i.item,
long i.oqua,
string err.msg(100))
{long ret
string rstr(30), value(10)
domain tcqsl1 o.qty
o.qty = i.oqua
stpapi.put.field("tdsls4101m000", "tdsls040.orno", str$(i.orno))
stpapi.find("tdsls4101m000")
stpapi.handle.subproc("tdsls4101m000", "tdsls4102s000", "add")
stpapi.continue.process("tdsls4101m000", err.msg)
stpapi.put.field("tdsls4102s000", "tdsls041.item", i.item)
stpapi.put.field("tdsls4102s000", "tdsls041.oqua", str$(o.qty))
ret = stpapi.insert("tdsls4102s000", 1, err.msg)
if ret = 0 then
rstr = err.msg
stpapi.recover("tdsls4102s000", err.msg)
else
stpapi.get.field("tdsls4102s000", "tdsls041.pono", value)
rstr=value
endif
stpapi.end.session("tdsls4102s000")
stpapi.end.session("tdsls4101m000")
return(rstr)
}
Here is the VBA code that calls the function (somewhat condensed for this example):
strDLL = "omySalesFunction"
lngSO = 123456
strItem = "BadItemCode"
lngQty = 1
strFunc = "add_line(" & lngSO & _
", " & Chr(34) & strItem & Chr(34) & ", " & _
lngQty & ", " & Chr(34) & Space(100) & Chr(34) & ")"
Set objBaan = CreateObject("Baan4.Application")
objBaan.ParseExecFunction strDLL, strFunc
varRetVal = objBaan.returnvalue
varErrVal = objBaan.Error
debug.print objBaan.functioncall
Sorry, this code is a bit rough still, and shows some trial and error.
When I run this, the functioncall is the same as the string I sent in ParseExecFunction, ie "add_line(123456, "BadItemCode", 1, "[100 spaces]").
I thought from all the examples I've seen that the last position of the functioncall would have contained the error code, instead of just 100 spaces, but it does not change.
The Baan DLL function right now returns "Item Not Found" in this case, instead of the position number. I want my VBA code to recongnize that it got an error back instead valid data. I know that I could just test for a long here, but I am trying to write generic code (a VBA class module actually) that will work in a variety of situations. The "Item Not Found" error does not generate anything reconginzed by objBaan.Error.
Is what I'm trying to do possible? Am I missing something?
Thanks,
Rob