Deki Djokic wrote:
Hello Drew,

Actually let me ask you this - how would you do it in MS Access - maybe we can find a similar approach in Base?
What I would like to do and what I have done with Access is that in frmInspection  value of  fmtWeek .Text was calculated according to value of DateField.Text and inserted in a table. To make it more clear: if user update/change Date, Week number (0-52) has to be automatically calculated and displayed in a DateField. And, yes, I want to use it from the form frmInspection.
Hope that I succeed to clarify a topic a bit.
A bit more complicated under Base, unfortunately.

The dataform has an event"Before record action". If we add the following procedure and function to a library and assignt the onBeforeRecordAction procedure to this event you will have the funcitonal equivilant to what you did in MSA.

sub onBeforeRecordAction( oEv as object )
	dim dtField
	dim wkField

	if oEv.Action = 2 then
		if oEv.Source.ImplementationName <> "com.sun.star.form.FmXFormController" then
			dtField = oEv.Source.getByName( "DateField" ).BoundField
			wkField = oEv.Source.GetByName( "fmtWeek" ).BoundField
			wkfield.updateInt( getWeek( oEv.Source.ActiveConnection, dtField.Value	) )
		end if
	end if
end sub

function getWeek( aConn as variant, aDate as new "com.sun.star.util.Date" )
	dim stmt
	dim rs
	
	stmt = aConn.CreateStatement
	rs = stmt.executeQuery( "CALL WEEK( '" & aDate.Year & "-" & aDate.Month & "-" & aDate.Day & "' ) " )
	rs.next
	getWeek = rs.getInt( 1 )
end function

One item woth mentioning is that the WEEK function does not use ISO8601 ( I think that is it ) numbering - instead it always starts with week 1 for the week containing JAN 1, so 2005-12-28 is week 53, not 52.

Drew

Reply via email to