I have been building a database to aid my home brewing efforts and have hit a wall trying to get a Timestamp value into a table using a macro. This is using a split HSQLDB database v2.3.2. I have a variable as: Dim dGravitydateUNO As New com.sun.star.util.DateTime, and can see that it is populated but running the macro results in ‘BASIC runtime error. Incorrect property value’. I have done a bit of reading around this but have so far drawn a blank. Any help offered would be welcome.
This is the macro with the issue arising within the final SQL string:
Sub FermTrack(oEvent As Object)
Dim oForm As Object
Dim oStatement As Object
Dim stSQL As String
Dim oResult As Object
Dim dFermdate As New com.sun.star.util.Date
Dim doFermepoch As Double
Dim dCaskdate As New com.sun.star.util.Date
Dim doCaskepoch As Double
Dim oDatabaseContext As Object
Dim oDatasource As Object
Dim oConnection As Object
Dim doFGActual As Double
Dim stTopic As String
Dim iFermID As Integer
Dim doGravity As Double
Dim doOGActual As Double
Dim dGravitydate As Date
Dim dGravitydateUNO As New com.sun.star.util.DateTime
Dim doGravityepoch As Double
Dim doGravitydate As Double
oForm = oEvent.Source.Model.Parent
iBrewID = oForm.getLong(1)
dFermdate = oForm.getDate(3)
dCaskdate = oForm.getDate(18)
doOGActual = oForm.getDouble(17)
MsgBox "Fermentation date = " & dFermdate.day & dFermdate.month & dFermdate.year
doFermepoch = CDateFromUnoDate(dFermdate)
doFermepoch = (doFermepoch -25569) * 86400
doCaskepoch = CDateFromUnoDate(dCaskdate)
doCaskepoch = (doCaskepoch -25569) * 86400
MsgBox "Fermentation date = " & doFermepoch
stTopic = "ispindelsuninn/I1_gravity"
oDatabaseContext = createUnoService("com.sun.star.sdb.DatabaseContext")
oDatasource = oDatabaseContext.getByName("Gravity")
oConnection = oDatasource.GetConnection("","")
oStatement = oConnection.createStatement()
stSQL = "SELECT ""id"", ""payload"", ""created_at"" FROM ""sensors_data"" WHERE ""created_at"" > "& doFermepoch &" AND created_at < "& doCaskepoch &""
oResult = oStatement.executeQuery(stSQL)
While oResult.Next
iFermID = oResult.getLong(1)
doGravity = oResult.getDouble(2)
doGravityepoch = oResult.getDouble(3)
If doGravity = doOGActual And oResult.row =1 Then
Elseif doGravity < doOGActual Then
doGravitydate = (doGravityepoch / 86400) + 25569
MsgBox "Gravity epoch = " & doGravityepoch & " Gravity date = " & doGravitydate
dGravitydate = CDate(doGravitydate)
MsgBox "CDate = " & dGravitydate
dGravitydateUNO = CDatetoUNODateTime(doGravitydate)
MsgBox " UNO = " & dGravitydateUNO.day & "/" & dGravitydateUNO.month & "/" & dGravitydateUNO.year & " " & dGravitydateUNO.hours & ":" & dGravitydateUNO.minutes & ":" & dGravitydateUNO.seconds
MsgBox "Brew ID= "& iBrewID &" FermID - "& iFermID &" Date= "& dGravitydate &" Gravity= "& doGravity
oStatement = oForm.ActiveConnection.createStatement()
stSQL = "INSERT INTO ""tblFermentation"" (""BrewID"", ""FermID"", ""Date"", ""Gravity"") VALUES ('"+ iBrewID +"','"+ iFermID +"', '"+ dGravitydateUNO +"', '"+ doGravity +"')"
oStatement.executeUpdate(stSQL)
doOGActual = doGravity
Endif
Wend
End Sub
Version: 25.8.0.4 (X86_64)
Build ID: 48f00303701489684e67c38c28aff00cd5929e67
CPU threads: 2; OS: Windows 10 X86_64 (build 19045); UI render: Skia/Raster; VCL: win
Locale: cy-GB (en_GB); UI: en-GB
Calc: threaded