Sub generate() On Error GoTo error: CBL.IniciaTransaccao Dim cblYear As Integer cblYear = Year(cblDate.Value) Dim query As String query = " select cl.id,cl.tipodoc,cl.numdoc,cl.serie, cl.ValorRec, s.valorpagocredito,s.valorpagodebito, s.armazem,s.cdu_espaco, artigo,valorpago, PagarReceber, '2'+ccustocbl + '2111' as cc from " & _ " CabLiq cl inner join tek_showreceiptdetails s on (s.idcabliq = cl.id) inner join " & _ " Armazens a on (a.Armazem = s.Armazem) where cl.CDU_Reconciliado='0' and " & _ " cl.tipodoc='" & docTypeCombo.Value & "' and cl.serie = '" & serieCombo.Value & _ "' and datediff(d,0,datadoc) between " & DateDiff("d", "1900-01-01", initialDTP.Value) & _ " and " & DateDiff("d", "1900-01-01", finalDTP.Value) & _ " order by id;" Dim sql As StdBELista Set sql = BSO.Consulta(query) Dim n As Integer n = 0 If Not sql.NoFim Then