Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

User count 1

Status
Not open for further replies.

Aietoe

Technical User
Nov 30, 2000
85
CA
An Access database is used by many users.

In a specific form, i would like to know at anytime the number of time a button was hit(cumulative count).

Thanks for your help.
 
set up a table in access, with three fields

Form_Name, Control_Name, Hit save as tblstats

then on the click event of the control in a form have the code like


dim mydb as database
dim myrec as recordset

set mydb = currentdb()
set myrec = mydb.openrecordset("Tblstats")

with myrec.addnew
!form_name = me.name
!Control_Name = whatever the name of the control is
!hit = 1
.update
end with

trick is to put it into a public funciton so you can call it anywhere in the db and pass teh fields as arguments then all you need to do is create a query and sum the totals of hits

or you could change it so it found the record for the control and jsut added one to the hit each time, as tehy say the choice is yours .....


 
Also, if you have user-level security enabled, you could include a username field in the table & populate it with CurrentUser(). This function returns the username - then you'd see who clicked how many times..... J. Jones
jjones@cybrtyme.com
 
of if you dont have level sercurity you could use

Private Declare Function GetUserName Lib "advapi32.dll" _
Alias "GetUserNameA" (ByVal lpBuffer As String, _
nSize As Long) As Long

and get tehre username that way ;-)
 
Hi!

Still have a little interrogation.

Whatif i'm already using the click even to call a macro?

Thanks
 
Hi Chance!
Here is how i coded your suggestion:

Private Sub Aperçu_Click()
Dim mydb As Database
Dim myrec As Recordset

Set mydb = CurrentDb()
Set myrec = mydb.OpenRecordset("Tblstats")

With myrec
.AddNew
!Form_Name = Me.Name
!Control_Name = Aperçu
!hit = 1
.Update
End With

End
End Sub
I get an error message "2427" on the name of my Control_Name
....
i also tried
"!Control_Name = [Formulaires]![Critères-M-A]![Aperçu]" and "!Control_Name = ([Formulaires]![Critères-M-A]![Aperçu])" and "!Control_Name = [Aperçu]" and !Control_Name =![Aperçu]"

What's wrong?

 
Great! it's working

Tank you VERY MUCH!

bye!
 
Great! it's working

Thank you VERY MUCH!

bye!
 
Hi Chance!

Another and hopefully last question...

Where do you put this declare to get the username?
If you could give me a few more details.

Private Declare Function GetUserName Lib "advapi32.dll" _
Alias "GetUserNameA" (ByVal lpBuffer As String, _
nSize As Long) As Long

Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top