Connecting Tech Pros Worldwide Forums | Help | Site Map

Writting data into a table with VB (I think)

John Ortt
Guest
 
Posts: n/a
#1: Nov 13 '05
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.






Jeff Smith
Guest
 
Posts: n/a
#2: Nov 13 '05

re: Writting data into a table with VB (I think)


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" <JohnOrtt@Idontwantspamsonoreturnaddress.com> wrote in message
news:414ea665$1_1@baen1673807.greenlnk.net...[color=blue]
> 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[/color]
will[color=blue]
> 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.
>
>
>
>
>[/color]


John Ortt
Guest
 
Posts: n/a
#3: Nov 13 '05

re: Writting data into a table with VB (I think)


That looks excellent Jeff.

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

John

"Jeff Smith" <NoWay@Not.This.Address> wrote in message
news:cimare$i3e$1@lust.ihug.co.nz...

<Snipped>


John Ortt
Guest
 
Posts: n/a
#4: Nov 13 '05

re: Writting data into a table with VB (I think)



"John Ortt" <JohnOrtt@Idontwantspamsonoreturnaddress.com> wrote in message
news:414eb151$1_1@baen1673807.greenlnk.net...[color=blue]
> That looks excellent Jeff.
>
> Thankyou for your time and I'll let you know how I get on.
>
> John
>[/color]

Worked a treat. Thanks Jeff.

Now to fill the code in for all the rest of the buttons :)


Closed Thread