Date Stamp on Query Execute

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is there a way to record and/or view the last time a query was executed
(without being modified)? I have a query being executed from a Form and
would like to monitor its usage. Thanks.
 
(just one person's opinion...)

I'm not aware of a property that a query has that would record "date/time
last run" for a query.

However, if you are working in a form, nothing would stop you from writing a
record in a table you create to store [QueryName] and [DateRun] at the same
time you run that query from the form. Then, the last time a give query was
run is the Max([DateRun]).

Regards

Jeff Boyce
<Office/Access MVP>
 
No. Access does not provide that kind of information to you.

If the query is being executed programmatically, you could write your own
log.
 
bocjoel said:
Is there a way to record and/or view the last time a query was executed
(without being modified)? I have a query being executed from a Form and
would like to monitor its usage.

There's nothing that will do that automatically. However,
you can create a custom property on the QueryDef object and
use a function to save a date/time value. Then your form's
code can run the query and set the property, e.g.

db.Execute "youractionquery"
SetQDefProp "youractionquery", "LastUsed", Now

Here's the procedure that deals with the QuerDef property:

Public Sub SetQDefProp(qname As String, _
propname As String, propval As Variant)
Dim db As DAO.Database
Dim qdf As QueryDef
Dim prp As Property

On Error GoTo ErrHandler

Set db = CurrentDb()
Set qdf = db.QueryDefs(qname)
qdf.Properties(propname) = propval

ExitHere:
Set qdf = Nothing
Set db = Nothing
Exit Sub

ErrHandler:
Select Case Err.number
Case 3270
Set prp = qdf.CreateProperty(propname, _
dbDate, propval)
qdf.Properties.Append prp
Set prp = Nothing
Case Else
MsgBox Err.number & "-" & Err.Description
End Select
Resume ExitHere
End Sub
 
Back
Top