SUB Current_Date_and_ID DIM oDatasource AS OBJECT DIM oConnection AS OBJECT DIM oSQL_Command AS OBJECT DIM stSql AS STRING DIM oResult AS OBJECT DIM oDoc AS OBJECT DIM oDrawpage AS OBJECT DIM oForm AS OBJECT DIM oField1 AS OBJECT DIM oField2 AS OBJECT DIM oField3 AS OBJECT DIM inIDnew AS INTEGER DIM inYear AS INTEGER DIM unoDate oDoc = thisComponent oDrawpage = oDoc.drawpage oForm = oDrawpage.forms.getByName("MainForm") oField1 = oForm.getByName("fmt_year") oField2 = oForm.getByName("fmtID") oField3 = oForm.getByName("dat_date") IF IsEmpty(oField2.getCurrentValue()) THEN IF IsEmpty(oField3.getCurrentValue()) THEN unoDate = createUnoStruct("com.sun.star.util.Date") unoDate.Day = Day(Date) unoDate.Month = Month(Date) unoDate.Year = Year(Date) inYear = Year(Date) ELSE inYear = oField3.CurrentValue.Year END IF oDatasource = ThisComponent.Parent.CurrentController If NOT (oDatasource.isConnected()) THEN oDatasource.connect() END IF oConnection = oDatasource.ActiveConnection() oSQL_Command = oConnection.createStatement() stSql = "SELECT MAX( ""ID"" )+1 FROM ""orders"" WHERE ""year"" = '" + inYear + "'" oResult = oSQL_Command.executeQuery(stSql) WHILE oResult.next inIDnew = oResult.getInt(1) WEND IF inIDnew = 0 THEN inIDnew = 1 END IF oField1.BoundField.updateInt(inYear) oField2.BoundField.updateInt(inIDnew) IF IsEmpty(oField3.getCurrentValue()) THEN oField3.BoundField.updateDate(unoDate) END IF END IF END SUB |