Sure, you could either use a table or a custom database property to store the
value, then, just increment it each time the form is opened. You could do
the same with the userid and date visited.
If you go the table route, you could create a table that contains fields
FormUseID, FormName, HitCounter, LastUser, LastAccess
If you wanted to do this for more than one form, I would create a subroutine
to do the update for you. Something like:
Public Sub FormUse(FormName as String)
Dim strSQL as String
if DCOUNT("FormUseID", "tbl_FormUse", "FormName = '" & FormName & "'") =
0 Then
strSQL = "INSERT INTO [" & FormName & "] (FormName, HitCounter,
LastUser, LastAccess) " _
& "Values ('" & FormName & "', 1, '" & fOSUserName() &
"', #" & Now() & "#)"
Else
strSQL = "UPDATE tbl_FormUse " _
& "SET [HitCounter] = [HitCounter] + 1, " _
& "[LastUser] = '" & fOSUserName() & "', " _
& "[LastAccess] = #" & Now() & "# " _
& "WHERE [FormName] = '" & FormName & "'"
End If
currentdb.execute strsql, dbFailOnError
Exit Sub
Then, in the forms open or load event, you would add a line that calls the
FormUse subroutine, something like:
Private Sub Form_Load
Call FormUse(me.name)
End Sub
If you then want to display the counter on your form, you would use the
DLOOKUP() function as the ControlSource for a textbox:
= DLOOKUP("HitCount", "tbl_FormUse", "FormName = 'frmWhatever'")
----
HTH
Dale
gillman54 said:
Hi,
Is it possible to insert a hit counter into a database form, also is it
possilble to display who last accessed a form and the date which they visited?
Thanks
Chris