By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,961 Members | 1,320 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,961 IT Pros & Developers. It's quick & easy.

Writting data into a table with VB (I think)

P: n/a
I wish to add usage records to a table to show how many times each of the
buttons on my main menu are used.

I am envisaging a table which contains the following data:

User: Button: Time:
Fred Suppliers 10/10/04 03:54:45

The user will be the name of the individual who clicks on the button.
The button will store the name of the button pressed and the time field will
store the time when it was pressed.

There are approximately 50 buttons on the main menu with even more on
subforms and user specific menus.

The best way to do this that I can see is to add code to the OnClick event
in the following manner:

Private Sub Button1_Click()
RecordNavigation(1)
End Sub
Private Sub Button2_Click()
RecordNavigation(2)
End Sub

Function RecordNavigation(ButtonNo)
//////////////////////////////////////////////////////////////////////////
??How do I then write the three fields into the database
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ \\\\\\\\\\\\\\\\\\\\\\\\
End Function

Any help would be greatly appreciated.

John.

P.S. I appologise if this is not the ideal NG but I am happy to repost it
elsewhere if somebody can rcommend a more appropriate one.

Nov 13 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Place the following code into a standard module.
************************************************** ******
Public Sub RecordNavigation(strButton As String)
On Error Goto RecordNavigation_Err
Dim db As DAO.Database
Dim rst As DAO.Recordset
Set db = CurrentDB
Set rst = db.OpenRecordset("YourTableName")
With rst
.AddNew
!User = HowYouGetTheUser'sName
!Button = strButton
!Time = Now()
.Update
End With
RecordNavigation_Exit:
On Error Resume Next
rst.Close
Set rst = Nothing
Set db = Nothing
Exit Sub
RecordNavigation_Err:
MsgBox Err.Description, vbInformation, "Record Navigation"
Resume RecordNavigation_Exit
End Sub
How to use.
**************
Private Sub Button1_Click()
YourOtherCodeBehindTheButton
RecordNavigation("YourButtonName")
End Sub

Private Sub Button2_Click()
YourOtherCodeBehindTheButton
RecordNavigation("YourButtonName")
End Sub

I'd advise to change the name of the "Time" field to something else to say
TimeActivated or TimeUsed or something similar. Time is a reserved name in
Access and can lead to conflicts between the field name and the built in
Time() function.

Jeff
"John Ortt" <Jo******@Idontwantspamsonoreturnaddress.com> wrote in message
news:41**********@baen1673807.greenlnk.net...
I wish to add usage records to a table to show how many times each of the
buttons on my main menu are used.

I am envisaging a table which contains the following data:

User: Button: Time:
Fred Suppliers 10/10/04 03:54:45

The user will be the name of the individual who clicks on the button.
The button will store the name of the button pressed and the time field will store the time when it was pressed.

There are approximately 50 buttons on the main menu with even more on
subforms and user specific menus.

The best way to do this that I can see is to add code to the OnClick event
in the following manner:

Private Sub Button1_Click()
RecordNavigation(1)
End Sub
Private Sub Button2_Click()
RecordNavigation(2)
End Sub

Function RecordNavigation(ButtonNo)
//////////////////////////////////////////////////////////////////////////
??How do I then write the three fields into the database
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ \\\\\\\\\\\\\\\\\\\\\\\\
End Function

Any help would be greatly appreciated.

John.

P.S. I appologise if this is not the ideal NG but I am happy to repost it
elsewhere if somebody can rcommend a more appropriate one.


Nov 13 '05 #2

P: n/a
That looks excellent Jeff.

Thankyou for your time and I'll let you know how I get on.

John

"Jeff Smith" <No***@Not.This.Address> wrote in message
news:ci**********@lust.ihug.co.nz...

<Snipped>
Nov 13 '05 #3

P: n/a

"John Ortt" <Jo******@Idontwantspamsonoreturnaddress.com> wrote in message
news:41**********@baen1673807.greenlnk.net...
That looks excellent Jeff.

Thankyou for your time and I'll let you know how I get on.

John


Worked a treat. Thanks Jeff.

Now to fill the code in for all the rest of the buttons :)
Nov 13 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.