bongielondy
26th November 2012, 10:37
I am trying to get data from baan to excel. the error that i get says there is a problem with the query. Maybe the problem is the table name. How can I see the table names in BAAN. i have attached the code and the screen shot.

mark_h
26th November 2012, 15:43
Are you sure ttadv348 is the correct table? That is a tools table. This table does not exist on my system. If it is the correct tableyou might want to confirm which company the table is in - a lot of tools tables are in company 000. Then your query would need to have ttadv348._compnr=0 added to it. Plus I did not see a screen shot of the error, but I would verify the table and company number first. Other than that the code looked okay to me. I pulled a piece of your code out:


Sub getItemDescrFromBaan()
Dim t As Range
Set t = Range("ServiceOrder")

query = "select ttadv348.* from ttadv348 where ttadv348.Customer ='TEB001'"

If Not startBaan Then Exit Sub
If Not GetCustomer(query) Then Exit Sub
If FetchNext(query_id) Then
t.Offset(, 1) = GetStrData("ttadv3480.ServiceOrder")
t.Offset(, 2) = GetStrData("ttadv3480.Installation")
QueryEnd (query_id)
Else
t.Offset(, 1) = "Unknown Item"
t.Offset(, 2).ClearContents
End If
End Sub
Function GetCustomer(ByVal query As String) As Boolean
GetCustomer = False
On Error Resume Next
baanObj.ParseExecFunction Query_dll, "olesql_parse(" & Chr(34) & query & Chr(34) & ")"
If Err.Number > 0 Then
Err.Clear
If startBaanReally Then
baanObj.ParseExecFunction Query_dll, "olesql_parse(" & Chr(34) & query & Chr(34) & ")"
Else
Exit Function
End If
If Err.Number > 0 Then
Err.Clear
Exit Function
End If
End If
query_id = Val(baanObj.ReturnValue)
If query_id = 0 Then
Application.StatusBar = Left(query, 80)
MsgBox ("Error in query" & Chr(10) & "(" & query & ")" & Chr(10) _
& "/ or no data within selection ? ...")
Else
GetQid = True
End If
End Function


And then a piece of some code I played with at one time:

uery = "select tiitm001.* from tiitm001 where tiitm001.item = 'PLM7249020'"

B_function = "olesql_parse(" & Chr(34) & Query & Chr(34) & ")"
' execute the function olesql_parse from DLL ottdllsql_query
BaanObj.ParseExecFunction "ottdllsql_query", B_function

query_id = Val(BaanObj.ReturnValue)
If query_id = 0 Then
MsgBox "function olesql_parse fails"
End If

' The function olesql_fetch reads one query result, in this example the (string) value of ttaad200.user
' The identification number of the query must be passed as argument to this function
B_function = "olesql_fetch(" & query_id & ")"
BaanObj.ParseExecFunction "ottdllsql_query", B_function
' Get Location
B_function2 = ""
temp_string = "tiitm001.ccur"
Supplier = String(32, " ")
B_function2 = "olesql_getstring(" & Chr(34) & temp_string & Chr(34) & "," & Chr(34) & Supplier & Chr(34) & ")"
BaanObj.ParseExecFunction "ottdllsql_query", B_function2
temp_string = BaanObj.FunctionCall
Location = Mid(temp_string, 35, 32)
Location = Trim(Location)