Run report only if date is not null

LO 7.1.2 HSQL 2.51 win10

Hi,

Struggling with a date check

How can I check for a null value of a date field of an existing record. Tried to adapt this code which works

Sub checkblanks

DIM oDoc AS OBJECT

DIM oDrawpage AS OBJECT

DIM oForm AS OBJECT

DIM oTable AS OBJECT

DIM oGrid AS OBJECT

DIM oColumnis AS OBJECT

DIM myid AS STRING

oDoc = thisComponent

oDrawpage = oDoc.drawpage

oForm = oDrawpage.forms.categoria.subcategoria.getByName(“subItem”)

oTable = oForm.getByName(“subBookings”)

oGrid = oTable.getByName(“tc1”)

oColumnis = oGrid.getByName(“bnos”)

myid = oColumnis.getCurrentValue()

MSGBOX "the value is " + myid

If myid <-1 Then

MSGBOX “noid”

EXIT Sub

endif

to this - but the null does not throw an error and still opens the report

oForm = oDrawpage.forms.categoria.subcategoria.getByName(“subItem”)

oTable = oForm.getByName(“subBookings”)

oGrid = oTable.getByName(“tc1”)

oColumnis = oGrid.getByName(“idate”)

mydt= oColumnis.getCurrentValue()

MSGBOX "the value is " + myid

If mydt = Null Then

MSGBOX “nodate”

EXIT Sub

endif

call OpenFactura

End Sub

appreciate any pointers, thanks

You are defining myid AS STRING. So it is no number. A blank string will be

IF myid = "" THEN
EXIT SUB
END IF

@RobertG Thanks, however does not make any difference and if I declare it as a date then
the line oColumnis = oGrid.getByName(“idate”) throws an error, however I can resolve the issue by way of adding a bolean and test for false.

Didn’t notice it was a date field. It will save the date in a struct:

oColumnis.CurrentValue.Day 
oColumnis.CurrentValue.Month
oColumnis.CurrentValue.Year

So could be

myid = oColumnis.CurrentValue.Day &  
       oColumnis.CurrentValue.Month &   
       oColumnis.CurrentValue.Year

will help to get an empty string, if there is no value inside.

@RobertG

Thanks , now I get a variable unknown error
oForm = oDrawpage.forms.categoria.subcategoria.getByName(“subItem”)
oTable = oForm.getByName(“subBookings”)
oGrid = oTable.getByName(“tc1”)
oColumnis = oGrid.getByName(“idate”)

myb = oColumnis.CurrentValue.Day & oColumnis.CurrentValue.Month & oColumnis.CurrentValue.Year
If myid = " " Then
MSGBOX “Ingrese una fecha de factura”
EXIT Sub
endif

See the variable myb. You are defining myb, not myid. And the value for this variable shouldn’t be a space (" "), it should be an empty string ("").

Hi @RobertG

Thanks again, made the adjustments but no success. Got it working with an additional
yes no field instead.