tyrell
11th January 2010, 17:38
Hello,
I'm trying to access Baan from VBScript.
The references to "Ole Automation Baan 4 1.1 Type Library" is checked in the "References" menu. The reference correctly points to "c:\Program files\baan\lib\bw.tlb". Is there another reference I should add ?
Baan IV is installed on a Unix server and the machine I'm making the tests on is Windows XP.
But I still get a "Undefined user type" or "Type défini par l'utilisateur non défini" in french.
Any idea?
Function Main()
Dim BaanObj As Baan4.Application ----> error message here!
Set BaanObj = CreateObject("Baan4.Application")
...
End Function
Thanks for your help !!
Stéphane
Fn Herstal
arthur_info
11th January 2010, 20:02
Hello Stéphane,
I'm using this code and it's working well (the code inserts a registry in the table tdcot974):
Dim BaanObj As Object
BaanObj = CreateObject("Baan4.Application.simulation")
try
Dim sSession As String
Dim sTable As String
Dim sField As String
Dim sValue As String
Dim ErrMessage As String = Space(30)
sTable = "tdcot974"
sSession = "tdcotd109m000"
sField = "orno.d"
sValue = "109918"
Ut.PopulateBaanField(BaanObj, sSession, sTable, sField, sValue)
(...)
Ut.CommitBaanInsert(BaanObj, sSession)
Ut.FinalizaBaan(BaanObj, sSession)
Catch ex As Exception
MsgBox("Erro ao executar comando no Baan. " & vbNewLine & "Msg: " & ex.Message)
BaanObj = Nothing
End Try
The ut functions:
Public Shared Function PopulateBaanField(ByVal BaanObj, ByVal sSession, ByVal sTable, ByVal sField, ByVal sValue) As String
' Preenchendo o campo Baan com o valor indicado
Dim s
s = "stpapi.put.field(" & Chr(34) & sSession & Chr(34) & ", " & _
Chr(34) & sTable & "." & sField & Chr(34) & ", " & _
Chr(34) & sValue & Chr(34) & ")"
BaanObj.ParseExecFunction("ottstpapihand", s)
If BaanObj.Error <> 0 Or BaanObj.ReturnValue <> "" Then
MsgBox("Erro ao inserir dados." & vbNewLine & _
"BaanObj.Error = " & BaanObj.Error & Chr(10) & _
"BaanObj.ReturnValue = " & BaanObj.ReturnValue & Chr(10) & _
"BaanObj.FunctionCall = " & BaanObj.FunctionCall)
BaanObj.Quit()
Return BaanObj.Error
Else
Return ""
End If
End Function
Public Shared Sub CommitBaanInsert(ByRef BaanObj As Object, ByVal sSession As String)
Dim sErrMsg = Space(50)
BaanObj.ParseExecFunction("ottstpapihand", "stpapi.enum.answer(" & Chr(34) & sSession & Chr(34) & "," & Chr(34) & "tdcot00013.d" & Chr(34) & ",1)")
BaanObj.ParseExecFunction("ottstpapihand", "stpapi.insert(" & Chr(34) & sSession & Chr(34) & ",1," & Chr(34) & sErrMsg & Chr(34) & ")")
If BaanObj.Error <> 0 Or BaanObj.ReturnValue <> "1" Then
MsgBox(Trim(Chr(10) & _
"sErrMsg = " & sErrMsg & Chr(10) & _
"BaanObj.Error = " & BaanObj.Error & Chr(10) & _
"BaanObj.ReturnValue = " & BaanObj.ReturnValue & Chr(10) & _
"BaanObj.FunctionCall = " & BaanObj.FunctionCall))
Else
MsgBox("Insert executado com sucesso.")
End If
End Sub
Public Shared Sub FinalizaBaan(ByRef BaanObj As Object, ByVal sSession As String)
If sSession <> "" Then
BaanObj.ParseExecFunction("ottstpapihand", "stpapi.end.session(" & Chr(34) & sSession & Chr(34) & ")")
End If
BaanObj.Quit()
BaanObj = Nothing
End Sub
Best regards,
Arthur Accioly
Vincent_Church
26th May 2012, 18:00
Hello all,
I am trying to run VBScript for opening certain session, but it doesnt work:confused:. I have similar code in Excel VBA and it works well. Can somebody see any mistake I made in VBS code?
VBS Code(not working):
Function Main()
Dim BaanObj
Dim sSession
Set BaanObj = CreateObject ("Baan.Application")
sSession = "tuhpc7501m000"
Call BaanObj.ParseExecFunction ("ottstpstandard", "zoom.to.menu(" & Chr(34) & sSession & Chr(34) & ",2," & Chr(34) & Chr(34) & "," & Chr(34) & Chr(34) & ",0,0)")
End Function
VBA Code (working):
Sub Y()
On Error Resume Next
Dim BaanObj As Object
Set BaanObj = CreateObject("Baan.Application")
BaanObj.ParseExecFunction "ottstpstandard", "zoom.to.menu(" & Chr(34) & "tuhpc7501m000" & Chr(34) & ",2," & Chr(34) & Chr(34) & "," & Chr(34) & Chr(34) & ",0,0)"
End Sub
Cheers,
Vincent