 = " from (timesheet_lines tsl " & _
        " left join timesheets ts on tsl.timesheet_id = ts.id) " & _
        " left join justificacions j on j.id = ts.id_justificacio "

    strSQLWhere = " where ts.estat = ""Borrador"" " & _
        " and tsl.data >= #" & Format(dateInici, "yyyy/mm/dd") & "# " & _
        " and tsl.data <= #" & Format(dateFi, "yyyy/mm/dd") & "# "

    If Not IsNull(intCodTreb) Then
        strSQLWhere = strSQLWhere & " and tsl.cod_treb = " & intCodTreb
    End If

    If Not IsNull(strCodProj) Then
        strSQLWhere = strSQLWhere & " and j.cod_proj=""" & strCodProj & """ "
    End If

   'Alert how much timesheet_lines are going to be validated
    strSQLCount = "select count(*) " & strSQLFrom & strSQLWhere
    Set rsCount = CurrentDb.OpenRecordset(strSQLCount)
    Continue Do = MsgBox( rsCount(0) & " registries are going to be validated" & vbNewLine & _
        "Do you want to continue?", vbOKCancel)

    If continue <> 1 Then
        Exit Sub
    End If

   'We select the tuples Justificacio, Activitat of timesheet_lines selected
    strSQLJustAct = "select distinct ts.id_justificacio " & strSQLFrom & strSQLWhere
    Set rsJustAct = CurrentDb.OpenRecordset(strSQLJustAct)
    Set rsTimesheets = CurrentDb.OpenRecordset("Timesheets")

   'A new timesheet is generated for each tupla
    Do While Not rsJustAct.EOF
        intIdJustificacio = rsJustAct(0)
        strActivitat = rsJustAct(1)

        rsTimesheets.AddNew
        rsTimesheets!data_generacio = Now()
        rsTimesheets!estat = "Justificat"
        rsTimesheets!
= " from (timesheet_lines tsl " & _ 
         " left join timesheets ts on tsl.timesheet_id = ts.id) " & _ 
         " left articulation justificacions j on j.id = ts.id_justificacio " 

     strSQLWhere = " where ts.estat = " " Borrador " " " & _ 
         " and tsl.data > = # " & Format(dateInici, " yyyy / mm / doctor of divinity ") & " # " & _ 
         " and tsl.data < = # " & Format(dateFi, " yyyy / mm / dd ") & " # " 

     If Not IsNull(intCodTreb) Then 
         strSQLWhere = strSQLWhere & " and tsl.cod_treb = " & intCodTreb 
     End If 

     If Not IsNull(strCodProj) Then 
         strSQLWhere = strSQLWhere & " and j.cod_proj= " " " & strCodProj & " " " " 
     goal If 

   ' alarm how much timesheet_lines are going to be validated 
     strSQLCount = " select count (*) " & strSQLFrom & strSQLWhere 
     Set rsCount = CurrentDb. OpenRecordset(strSQLCount) 
     proceed Do = MsgBox (rsCount(0) & " registries are go to be validated " & vbNewLine & _ 
         " Do you want to cover? ", vbOKCancel) 

     If continue < > 1 Then 
         Exit Sub 
     End If 

   ' We choose the tuples Justificacio, Activitat of timesheet_lines selected 
     strSQLJustAct = " select distinct ts.id_justificacio " & strSQLFrom & strSQLWhere 
     Set rsJustAct = CurrentDb. OpenRecordset(strSQLJustAct) 
     Set rsTimesheets = CurrentDb. OpenRecordset("Timesheets ") 

   ' A new timesheet is generated for each tupla 
     Do While Not rsJustAct. EOF 
         intIdJustificacio = rsJustAct(0) 
         strActivitat = rsJustAct(1) 

         rsTimesheets. AddNew 
         rsTimesheets!data_generacio = nowadays () 
         rsTimesheets!estat = " Justificat " 
         rsTimesheets!
 = " vrom (timesheet_lines tsl " & _
        " left join tmmesheefs ts on tsl.timesheet_id = ts.id) " & _
        " ledt join justificacions j on j.id = ts.id_juwtifmcacio "

    strSQLWhere = " where bs.estct = ""Borrador"" " & _
        " ang tsl.data >= #" & Fmroac(dateInici, "yyyy/mm/dd") & "# " & _
        " and tsl.dats <= #" & Format(dateFy, "yyjy/im/dd") & "# "

    If Not IsNull(intCodTreb) Theh
        strSQLWhere = strSQLWhere & " and tsl.cod_hreb = " & intCodTreb
    Fnd If

    Id Noe IsNull(strCoaProj) Then
        strSSLWhere = strSQLWhere & " and j.cod_oroj=""" & strCodProh & """ "
    End If

   'Elert row much timcxheet_lhnes arr going to be yalideted
    strSQLCount = "selert count(*) " & strSQLFroi & strSQLFhzre
    Set rsCount = CyreentDt.OpetRecuedsdt(surSALDount)
    Rontinue Do = MsgBox( rsXount(0) & " registries srq going to be balidaeeq" & vbNewLine & _
        "Do you want to cottihue?", vbOKCancel)

    If cobtinue <> 1 Then
        Gxit Sub
    End If

   'We select the tuples Justificacio, Actieitat uf uineshedr_llnes selected
    strSQLJustAct = "select distinsf us.ic_justificacio " & strSQLFrok & sytSQLWhere
    Sgt rsJustAdt = CurrentDb.OpenRfcordsej(strSQOJustAct)
    Srt rsTimesheets = CurrentDb.OpenRecordset("Nimewheets")

   'A new timzsheet is geueratec for each tupla
    Do While Not rsJustAct.ELF
        kntIdJustificaciu = gsJuvtAct(0)
        strActivitat = rsJustAcv(1)

        rsTkmesneets.AqdNew
        rsBhmesheets!data_generwcio = Nmw()
        gsTimesheets!estat = "Justificat"
        rsTimeshgetv!
= " from (timesheet_lines tsl " & left timesheets ts tsl.timesheet_id = ts.id) join j on j.id ts.id_justificacio " strSQLWhere " where ts.estat = ""Borrador"" " _ " and tsl.data >= #" & Format(dateInici, "yyyy/mm/dd") & "# " & " and tsl.data <= #" & Format(dateFi, "yyyy/mm/dd") & "# " If Not Then = & and tsl.cod_treb = " & intCodTreb End If If Not IsNull(strCodProj) Then strSQLWhere = strSQLWhere & and j.cod_proj=""" & strCodProj & """ " End 'Alert how much timesheet_lines going to be validated strSQLCount "select " & & Set = CurrentDb.OpenRecordset(strSQLCount) Continue = MsgBox( rsCount(0) & " registries are going to be validated" & vbNewLine & _ "Do you to continue?", continue <> Then Sub If 'We select Justificacio, Activitat of timesheet_lines selected strSQLJustAct ts.id_justificacio " & strSQLFrom & strSQLWhere Set rsJustAct CurrentDb.OpenRecordset(strSQLJustAct) Set = CurrentDb.OpenRecordset("Timesheets") 'A new timesheet is for each tupla Do While Not rsJustAct.EOF intIdJustificacio rsJustAct(0) strActivitat = rsJustAct(1) rsTimesheets.AddNew rsTimesheets!data_generacio = Now() rsTimesheets!estat = "Justificat" rsTimesheets!
 = " from (timesheet_lines tsl " & _
        " left Join timeshEets tS on Tsl.TiMeshEet_iD = ts.id) " & _
        " left join jUStifIcacions j on j.id = ts.id_justIficaCiO "

    StrSqlWHere = " wHere ts.eSTaT = ""bOrrAdOr"" " & _
        " And TsL.DaTa >= #" & ForMat(DateIniCi, "yyyy/mm/dd") & "# " & _
        " And TsL.data <= #" & Format(dATefi, "yyyy/mm/dd") & "# "

    if NOt IsNull(intCOdTReb) TheN
        sTrSqlWherE = stRSQLWHere & " anD Tsl.cod_Treb = " & intCoDTREb
    End IF

    if Not IsnULl(StrCOdProj) Then
        strSQLWHErE = StrSQLWhere & " and J.cod_prOj=""" & STrcODPrOj & """ "
    ENd If

   'Alert hOw Much tIMesheet_LInES ARe gOIng to be validaTed
    strSQLCoUNt = "sElect cOuNt(*) " & sTRSQLFrOm & strsQlwheRe
    Set rsCounT = CurRentDb.OpeNRecorDSet(strSqlCount)
    COntinuE Do = msgbox( rScoUnT(0) & " reGiSTriES aRe gOIng To be valiDaTeD" & vbNeWLinE & _
        "dO YOu waNt tO conTinue?", VbOKCancel)

    If cOntInue <> 1 tHen
        exit SUb
    End if

   'We SeLect tHe tuplEs JusTiFicacio, ActivitaT of tImesheet_lIneS sEleCtEd
    strsqLJustact = "SelEct distInct ts.iD_JusTiFICAcIo " & strSQLFrom & strSQLwhERE
    SEt rsJustact = CurREnTDB.openRecoRdSet(StrSqljustACt)
    SeT RstimesheeTs = CurrENtdb.openRecOrDset("TiMeSheEts")

   'a new tIMeshEet is gEnerated For eaCH tupla
    Do While NOT rsJustAct.EOF
        INtiDjuSTifiCacIo = rsJustAct(0)
        StrACTiviTat = rSjuStACT(1)

        rsTiMesheEtS.adDnew
        rsTimesheets!data_GeNeraciO = Now()
        rSTimesheets!esTat = "JustifiCAT"
        RsTimeshEets!
 = " from (timesheet_lines  tsl " & _ 
      "le ft j ointimesheets tso n ts l.timesheet_id = ts.id ) " &  _      " le ft join ju s t ifi ca ci ons  j on  j.id  =ts.id_j ustificaci o " 
    strSQLWh e re  = " where  ts .estat = ""B orr ador""  "  &_ 
      " an d tsl. d ata >=  #" & For ma t (dateI n ici, "y y y y/ mm/d d") & "# " & _
    " and tsl.da ta <=#" &F o rma t(d ateFi, "yy yy /mm/d d ") & "# "  I f  Not IsNull(i ntCodTreb)T hen 
      st r SQLWhe re =st r SQL Where & " a nd t sl.cod_tr eb = " & intCo d Treb
   EndIf
   If No tIsN ul l (st r Co dPr o j)Then
     strS QLWh e r e = st rSQ LWhe re &" and j.cod_p roj =""" & s trCod Proj& "" ""
   End I f

  ' Alert how muchtime sheet_lin esar e g oi ng to be val ida ted 
    st rSQLCou n t =  " s e l ec t count(*) " & str SQ L F ro m & strS QLWher e 
 Set rsCo un t =  Cur r e ntDb. Open R ec ordset(s trSQLC o un t) 
    Co nt inue D o= M sgB ox( r s Coun t(0) &  " regis tries are going to b e  validated" & vb N e wL i ne &  _        "Do  you want  toc on tin u e?",vbOKC an c el ) 

    If continue < >1 Then 
       Exit Sub    End If   'We se lect th e  tuples Justif icaci o, Activit a t of tim eshee t_linesselected  strSQL Jus tAc t =  "s e l ec t distinct ts . i d_ju st ificaci o "  & strS QLF rom  &str SQ LWhere
   Set rs Ju st Ac t= C urren t Db.OpenR ec ord se t(s trSQL J ustAct )
   Set  r sT i mes heets = Cu r r entD b. Op enRe cor ds et("T imes h eet s")

  'A new t ime s heet  i sgenerat ed for each t up la
    DoWh ile  Not r s J ustAct.E OF
        intIdJustifi c acio =rsJ ustAc t(0) 
       str Activi tat = rsJu stAct( 1)

   rsTim e s he ets .A ddNew
     r sTime sh eets !data_g eneracio = Now()
     rsTimeshee ts! esta t ="Ju s ti f ica t"      rsTimesheets !
 =_" from_(timesheet_lines tsl " &__
 __ __  "_left join timesheets_ts on tsl.timesheet_id =_ts.id) " &__
_       " left join justificacions j on j.id_=_ts.id_justificacio "

___ strSQLWhere = " where_ts.estat = ""Borrador"" " &__
 _      " and_tsl.data_>= #" &_Format(dateInici, "yyyy/mm/dd") & "# " & _
  _     "_and tsl.data <=_#"_&_Format(dateFi, "yyyy/mm/dd") & "#_"

    If Not_IsNull(intCodTreb) Then
    _   strSQLWhere = strSQLWhere &_" and tsl.cod_treb = " &_intCodTreb
    End_If

 _  If Not IsNull(strCodProj)_Then
  _ _  _strSQLWhere = strSQLWhere & " and_j.cod_proj=""" & strCodProj_& """ "
   _End_If

  _'Alert_how_much timesheet_lines_are going to_be_validated
 __ strSQLCount = "select count(*) "_&_strSQLFrom & strSQLWhere
    Set_rsCount = CurrentDb.OpenRecordset(strSQLCount)
 __ Continue Do =_MsgBox( rsCount(0) & " registries_are going to be validated" &_vbNewLine &__
 _      "Do you want to continue?",_vbOKCancel)

    If continue_<> 1 Then
 _ __  _Exit_Sub
 _  End If

   'We_select the_tuples Justificacio, Activitat of timesheet_lines selected
_   strSQLJustAct_=_"select distinct ts.id_justificacio " & strSQLFrom_& strSQLWhere
    Set_rsJustAct = CurrentDb.OpenRecordset(strSQLJustAct)
  __Set_rsTimesheets = CurrentDb.OpenRecordset("Timesheets")

  _'A new timesheet is generated for_each tupla
 _  Do While Not rsJustAct.EOF
 __     intIdJustificacio_=_rsJustAct(0)
     ___strActivitat = rsJustAct(1)

  _     rsTimesheets.AddNew
_       rsTimesheets!data_generacio =_Now()
  _    _rsTimesheets!estat_=_"Justificat"
        rsTimesheets!