what seems strange to me is you are asking for the numeric value with sys(11, fieldname), then you are val() that result. That seems like double work to me or that it should be failing.
and DOW() is expecting a date or time value, and you are sending a character string with sys(10, fieldname).
I think that you have those to sys calls reversed. Can you try changing the 11's to 10's and the 10's to 11's?
HTH
Beth
>
> trecib=(val(sys(11,tablest.freciborep))-val(sys(11,tablest.fech_fin)))
> XLSheet.Cells(i+1,13).value = TRECIB
> fec1=val(sys(11,tablest.fech_fin))
> fec2=val(sys(11,tablest.freciborep))
> contador=0
> do while fec1<>fec2
> if dow(sys(10,(fec1))=1 or dow(sys(10,fec1))=7
> contador=contador+1
> endif
> fec1=fec1+1
> enddo
>