can you place the adjusted code?
This is the code
Code:
Private Sub BtnNieuweOpleidingsuren_Click()
DoCmd.RunCommand acCmdSaveRecord
MsgBox "De gegevens zijn opgeslaan"
Dim yearr As Integer
Dim nextYear As Integer
Dim landmeterID As String
Dim SQL As String
Dim SQL1 As String
Dim rs As DAO.Recordset
Dim rs1 As DAO.Recordset
Dim i As Integer
Dim currentYear As Integer
Dim hours_followed As Integer
Dim exemption_this_year As Integer
Dim total_hours_this_year As Integer
Dim transaction As Integer
Dim total_hours_next_year As Integer
Dim exemption_next_year As Integer
Dim result As Integer
Dim Jaar As Integer
Dim verplichtJaar As Integer
Dim hours_followed_valid As Integer
Dim total_hours_next_year_valid As Integer
Dim exemption_next_year_valid As Integer
LanIDTxt.SetFocus
landmeterID = LanIDTxt.Text
Jaar = year(Me.startdatumTxt)
SQL = "Select Id_jaar from dbo_Lan_verplichtejaaropleiding where Id_landmeter = '" & landmeterID & "' and Id_jaar >=" & Jaar & " order by Id_jaar asc"
Set rs = CurrentDb.OpenRecordset(SQL)
Do While Not rs.EOF
'Get the date from this year
yearr = rs!Id_jaar
hours_followed_valid = DCount("uren", "dbo_Lan_opleiding", "Id_landmeter ='" & landmeterID & "' and Year(datumopleiding) = " & yearr & "")
Debug.Print hours_followed_valid
If (hours_followed_valid > 0) Then
hours_followed = DSum("uren", "dbo_Lan_opleiding", "Id_landmeter ='" & landmeterID & "' and Year(datumopleiding) = " & yearr & "")
End If
exemption_this_year = DLookup("Urenvrijgesteld", "dbo_Lan_vrijstelling", "Id_landmeter = '" & landmeterID & "' and Jaar = " & yearr & "")
total_hours_this_year = DLookup("Uren", "dbo_Lan_verplichttevolgen", "Jaar = " & yearr & "")
'Calculate the amount of hours to transfer
transaction = total_hours_this_year - exemption_this_year - hours_followed
'Get the data from next year
nextYear = yearr + 1
total_hours_next_year_valid = DCount("Uren", "dbo_Lan_verplichttevolgen", "Jaar = " & nextYear & "")
If (total_hours_next_year_valid > 0) Then
total_hours_next_year = DLookup("Uren", "dbo_Lan_verplichttevolgen", "Jaar = " & nextYear & "")
End If
exemption_next_year_valid = DCount("Urenvrijgesteld", "dbo_Lan_vrijstelling", "Id_landmeter = '" & landmeterID & "' and Jaar = " & nextYear & "")
If (exemption_next_year_valid > 0) Then
exemption_next_year = DLookup("Urenvrijgesteld", "dbo_Lan_vrijstelling", "Id_landmeter = '" & landmeterID & "' and Jaar = " & nextYear & "")
End If
If (transaction < 0) Then
result = total_hours_next_year - exemption_next_year + transaction
Else
MsgBox "De Landmeter heeft te weinig uren gevolgd!"
End If
CurrentDb.Execute "update dbo_Lan_verplichtejaaropleiding set te_volgen_uren =" & result & " where Id_jaar =" & nextYear & " and Id_landmeter = '" & landmeterID & "'"
' Debug.Print yearr; hours_followed; exemption_this_year; total_hours_this_year; transaction
'End If
rs.MoveNext
Loop
'End If
rs.Close
Forms![MainForm]![OpleidingOverzichtList].Requery
'Forms![MainForm]![OpleidingOverzichtList].Form.Requery
'[Forms]![MainForm]![OpleidingOverzichtList].Form.Requery
End Sub