pedromrs
29th October 2002, 16:26
Hi all,

What is the correct format to pass a date to put.field using OLE automation? I have tried to pass a string like "05122002" or "20020314" and I get a messed date in the first case and the current date in the second (I suppose the formats are invalid).
I'm not using Baan DLL's for this.
I have searched the forum and didn't find an answer to this one (well sort of but it doesn't solve my problem).

Thanks in advance :),

mark_h
29th October 2002, 17:16
Did you check this post (http://www.baanboard.com/baanboard/showthread.php?s=&threadid=1269&highlight=Date).


Mark

pedromrs
29th October 2002, 19:03
Hi Mark,

I guess I don't know how to search hehe. :rolleyes:
I tried using VB AND date and I guess date would be enough, strange it didn't show up this tough. Maybe I skipped it.

BTW, I was looking on how to make SQL queries trough Baan from VB, I guess this is possible but I didn't find anything in the stpapi DOC. Is it in a different DLL, if so is there a DOC for it?

Thanks once more,

mark_h
29th October 2002, 19:27
I do not know of an OLE document, most of it I figured out from the Baan examples. Below is a sample query example I used once from Excel. Hope this helps.

Mark


Sub lookup_cost()
Dim lcost As Long

Query = "select tdpur980.pric from tdpur980 " & _
"where tdpur980.item = " & Chr(34) & Chr(34) & partnumber & Chr(34) & Chr(34) & _
" and tdpur980.cprj = " & Chr(34) & Chr(34) & " BFBR" & Chr(34) & Chr(34)
B_function = "olesql_parse(" & Chr(34) & Query & Chr(34) & ")"
BaanObj.ParseExecFunction "ottdllsql_query", B_function

' If this function fails the ReturnValue is equal to zero, otherwise
' the function olesql_parse returns a identification number of the query
' Convert the (string) ReturnValue to a long variable using the function Val
query_id = Val(BaanObj.ReturnValue)
If query_id = 0 Then
MsgBox "function olesql_parse fails"
End If

' Fetch the record
B_function = "olesql_fetch(" & query_id & ")"
BaanObj.ParseExecFunction "ottdllsql_query", B_function
If BaanObj.ReturnValue = 0 Then
' retrieve query result and store it in the second argument of the function olesql_getstring
' Get Setup Time Number
cost = 999999.9999

temp_string = "tdpur980.pric"
B_function2 = "olesql_getfloat(" & Chr(34) & temp_string & Chr(34) & "," & cost & ")"
BaanObj.ParseExecFunction "ottdllsql_query", B_function2
temp_string = BaanObj.FunctionCall
temp_string = Mid(temp_string, 30, 15)
value_string = ""
found = False
For i = 1 To 15
If ((Asc(Mid(temp_string, i, 1)) >= 48 And Asc(Mid(temp_string, i, 1)) <= 57) Or _
(Asc(Mid(temp_string, i, 1)) = 46)) Then
value_string = value_string & Mid(temp_string, i, 1)
found = True
Else
If (found) Then
Exit For
End If
End If
Next i
cost = Val(value_string)
End If
Sheets(1).Cells(row, 10) = cost
End Sub

pedromrs
29th October 2002, 22:50
Hi Mark,

I'm getting out of words to thank you hehe. :cool:

Regarding the dates Baan uses in fact a strange format.
When I use get.field to return a date value it returns a number much like what Excel returns with the DateValue() function.

I guess I will have to use Bann functions to convert it.

Thanks once more,

Al Smith
29th October 2002, 23:36
Hi,
What I use to pass dates to Baan is CLng(Date)+693594.
Baan dates are held as a number representing the number of days since 01/01/0001.
VB (and Excel and etc.) also hold dates as a number but they represent the number of days since 01/01/1900.
The number 693594 is the number of days between 01/01/0001 and 01/01/1900.
Al.

pedromrs
30th October 2002, 00:24
Hi Al,

Thanks for the answer.
In a search I did about the Excel format I found the explanation about it.
I never tought of looking for an older date to that of 1900. :confused:
I wonder why they do this?
Maybe it helps cross-platform (date fields in database) integration?

BTW, I'm using C# to interface with the OLE object.
I have this thing with VB hehe.
I wrapped the stpapi functions in a C# class so it's easier to call them from code. Helps to hide those string manipulation functions.

Except the issues I'm having from being a newbie (state on which I would be forever if it wasn't for the excel examples and
bannboard.com) in Baan and the OLE object (example this date thread :D ) I only had one problem with the tccom0101m000 session until now.
When I do an stpapi.insert with an existing employee number, instead of getting a text message
I get a code (tccom04.... [I don't have it with me right now, I'm recalling it from memory, I will get it tomorrow]).
This is weird since I get all the other messages similar to what I get trough the Baan Client.
Is this a common case? [By now you're all thinking: "When does this guy stop asking questions and closes the thread?" ;) ]

chaporon
8th April 2007, 20:14
Thanks Al_Smith, i search for a long time and i don't find a solution for my problem of date format.

CLng(Date)+693594 is very great.