zelarra821
Registered User.
- Local time
- Today, 13:38
- Joined
- Jan 14, 2019
- Messages
- 813
Hello. I have a table where I keep the days on which a given event occurred.
What I want is to search for a specific date (I have done this), and, if it does not coincide with any of the saved dates, search for the closest previous one.
For example:
4-jan-22
6-jan-22
9-jan-22
13-jan-22
If I search for January 9th, I want it to be positioned in the record for January 9th. However, if I search for January 8th, I want it to position on January 6th.
I want to do it with bookmarks.
This is the code I have
Thank you.
What I want is to search for a specific date (I have done this), and, if it does not coincide with any of the saved dates, search for the closest previous one.
For example:
4-jan-22
6-jan-22
9-jan-22
13-jan-22
If I search for January 9th, I want it to be positioned in the record for January 9th. However, if I search for January 8th, I want it to position on January 6th.
I want to do it with bookmarks.
This is the code I have
Code:
Sub ChooseDate(FName As Form)
Dim first As DAO.Recordset
Dim Date As String
Date = Format(InputBox("Choose the date you want to search for.", DBName), "mm/dd/yyyy")
If StrPtr(Date) = vbEmpty Then Exit Sub
If Date = "" Then Exit Sub
Set rst = FName.Recordset
rst.FindFirst "Date=#" & Date & "#"
If Not first.NoMatch Then
FName.Bookmark = rst.Bookmark
else
rst.FindPrevious "Date=#" & Date & "#"
If Not first.NoMatch Then
FName.Bookmark = rst.Bookmark
else
MsgBox "There are no records for that date.", vbInformation, DBName
End If
End If
Set first = Nothing
End Sub
Thank you.