Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Function SearchNearest(intSearch As Integer) As Integer
- Dim DB As DAO.Database
- Dim RS As DAO.Recordset
- Dim strSQL, strMax, strMin As String
- Dim intMax, intMin As Integer
- Dim intDifMax, intDifMin As Integer
- Set DB = CurrentDb
- strSQL = "SELECT TOP 1 BuchArtikel_ID FROM Buchung WHERE BuchArtikel_ID <= " & CStr(intSearch) & " ORDER BY Buchung.BuchArtikel_ID DESC;"
- Set RS = DB.OpenRecordset(strSQL)
- If RS.RecordCount > 0 Then
- intMin = RS!BuchArtikel_ID
- Else
- intMin = 0
- End If
- strSQL = "SELECT TOP 1 BuchArtikel_ID FROM Buchung WHERE BuchArtikel_ID >= " & CStr(intSearch) & " ORDER BY Buchung.BuchArtikel_ID ASC;"
- Set RS = DB.OpenRecordset(strSQL)
- If RS.RecordCount > 0 Then
- intMax = RS!BuchArtikel_ID
- Else
- intMax = 0
- End If
- intDifMax = (intSearch - intMax) * -1
- intDifMin = intSearch - intMin
- Debug.Print intDifMax
- Debug.Print intDifMin
- If intDifMin > intDifMax Then
- SearchNearest = intMax
- Else
- SearchNearest = intMin
- End If
- RS.Close
- DB.Close
- Set DB = Nothing
- Set RS = Nothing
- End Function
Advertisement
Advertisement