Private Sub GetLastImage()
On Error GoTo ErrorHandler
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strSql As String
Dim strCriteria As String
strCriteria = Me.EventPath
strSql = "SELECT ImagePath, ImageName, DateCreated From tblImageFiles WHERE ImagePath = '" & strCriteria & "' ORDER BY DateCreated DESC"
Set db = CurrentDb
Set rs = db.OpenRecordset(strSql)
'Since table is sorted by date descending, the newest file is first. Extract the date
With rs
If rs.EOF Then
MsgBox "No records for " & strCriteria, vbOKOnly, CurrentProject.nam
Exit Sub
End If
.MoveFirst
dteLastDate = rs![DateCreated]
Me.txtLastImage = dteLastDate
End With
Requery 'this executes Form Current
ExitSub:
rs.Close
db.Close
Set rs = Nothing
Set db = Nothing
Exit Sub
ErrorHandler:
Dim Msg As String
MsgBox Msg, , "Error" & Str(Err.Number), Err.HelpFile, Err.HelpContext
Resume ExitSub
End Sub