Create a simple counter?

D

Doug_C

Hello,

I was wondering if it is possible to create a counter so people can see how
often a certain record was viewed? So each time someone looks up that record,
it will automatically add one to the total.

Thanks!
 
D

Douglas J Steele

Assuming the lookup is always done through a form, you could put logic in
the form to update the counter.

If you're not using a form, then no, there's no way.
 
D

Doug_C

Yes, I would have a form. What logic would I use to make the number increase
by one everytime someone looked at that record?
 
D

Douglas J Steele

Depends on what kind of form you've got, but generically you could put logic
to update your counter in the form's Current event.


Dim strSQL As Stirng

If DCount("*", "MyCounterTable", "RecordId = " & Me.Id) = 0 Then
strSQL = "InsertInto MyCounterTable (RecordId, CounterValue) " & _
"Values(" & Me.Id & ", 1)"
Else
strSQL = "UPDATE MyCounterTable " & _
"SET CounterValue = CounterValue + 1 " & _
"WHERE RecordId = " & Me.Id
End If

CurrentDb.Execute strSQL, dbFailOnError

This assumes that you have a table named MyCounterTable with two fields:
RecordId and CounterValue, and that you've got a simple Id to identify the
record that was just read.
 
Top