Wrox Programmer Forums
|
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 24th, 2007, 03:33 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 518
Thanks: 0
Thanked 0 Times in 0 Posts
Default user id during data entries

I am developing db company projects informations in MS Access 2007.
Different users are entering the data records by
different forms.

How can find / keep records that which users enter this informations /
records ?

what properties will use to keep / records users name or user id
that this records entery by that user ?

Please help to provide support / steps to keep users data entry
records ?

Thanks and regards

Mateen


 
Old December 26th, 2007, 08:14 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

This is a fairly common solution.
On your tables that you want to keep this information, add four fields:

DateCreated - Date
WhoCreated - text
DateModified - Date
WhoModified - text

This will keep a record of who created the record and when, and who last modified the record. If you want to keep a record of every transaction, then we can do that as well, but that is another post.

On the DateCreated field, add this as the Default Value: Now()

On the forms where data entry will happen for your tables, add all four new fields to the form, and set their Visible property to No. Then on the Before Insert event for the form, add this code:

Me.WhoCreated = (Environ$("Username"))

This will take the user's name and add it to the record as it is created.

On the same form's Before Update event, add this code:

Me.DateModified = Now()
Me.WhoModified = (Environ$("Username"))

This is the simplest solution but has limitations. If you want a transaction record for each transaction, then I would suggest sending the records to another database somewhere on the network, and then using the current and old values for each field.

Did this help?


mmcdonal

Look it up at: http://wrox.books24x7.com
 
Old January 3rd, 2008, 03:10 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 518
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for your response.

I following the steps as describe above.

DateCreated
DateModified

It keeping records in DateCreated and DateModified fields but

WhoCreated
WhoModified

it is not keeping /recording the records WhoCreated and WhoModified ?

I use your code in before insert and before update event like this

Private Sub Form_BeforeInsert(Cancel As Integer)
Me.WhoCreated = (Environ$("Username"))
End Sub

Private Sub Form_BeforeUpdate(Cancel As Integer)
Me.DateModified = Now()
Me.WhoModified = (Environ$("Username"))
End Sub

how can keep records / recording of whocerate and whomodified the records
every transaction ?

what property will need to change / update ?

Thanks and regards
Mateen





 
Old January 3rd, 2008, 08:18 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Try this:

Dim sWho As String
sWho = (Environ$("Username"))
MsgBox sWho

Put this on a button or something and see if it is taking the environment variable to the string. If that works, then do this:

Dim sWho As String

sWho = (Environ$("Username"))

Me.WhoCreated = sWho

Did that work?


mmcdonal

Look it up at: http://wrox.books24x7.com
 
Old January 7th, 2008, 07:01 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 518
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for your response.
I put above code on button click event

Dim sWho As String
sWho = (Environ$("Username"))
MsgBox sWho

but when I click no message display, no response.

how can get / store the username who is inserting the data ?

Thanks and regards
Mateen


 
Old January 7th, 2008, 08:36 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Try this then:

Dim objNet as Variant
Dim sUser As String

Set objNet = CreateObject("WScript.Network")
sUser = objNet.UserName

Me.WhoCreated = sUser

or

Me.WhoModified = sUser

Of course I should have asked if your users are using Windows or some other OS.


mmcdonal

Look it up at: http://wrox.books24x7.com
 
Old January 8th, 2008, 08:31 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 518
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for your response
I use above code in before insert and before update event.

Dim objNet as Variant
Dim sUser As String

Set objNet = CreateObject("WScript.Network")
sUser = objNet.UserName

Me.WhoCreated = sUser

both option but it not recording whocreated and whomodified records in respective fields.
but it recording the DateCreated , DateModified.

I am using windows vista MS office 2007 access.

regards
Mateen



 
Old January 8th, 2008, 10:06 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Sorry to hear that about using Vista and Access 2007, both iffy products. I can't even get the events to fire at all in Access 2007 in XP. I will look around for security settings. I am not sure what is going on but I think it has to do with sandbox problems.


mmcdonal

Look it up at: http://wrox.books24x7.com
 
Old January 8th, 2008, 10:20 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Okay, I found out how to turn off the macro seucrity in Chapter 2 - The Basics of Writing and Testing VBA Code, Beginning Access 2007 VBA
by Denise Gosnell (Wrox Press © 2007), and now I am thinking that you will need PowerShell commands since it is Vista.

I got this code to work as last posted by me in Access 2007 on Windows XP. Let me look up some Vista stuff.




mmcdonal

Look it up at: http://wrox.books24x7.com
 
Old January 8th, 2008, 10:31 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 126
Thanks: 5
Thanked 0 Times in 0 Posts
Default

Mateen,
I don't know if this will help...I have not used Vista or MS Office 2007...but I guess anything is worth a try when working on newer software and operating systems.

(I obtained this module code from "Real World Microsoft Access Database Protection and Security" by Garry Robinson.)
Create a module and put this in it:
Code:
Public Declare Function GetUserName Lib "advapi32.dll" _
  Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Public Function User_FX() As String
'fxP     --------------------------------------------------------
'fxP
'fxP-->  User_FX - Return the NT/Win2000/XP Account as a string
'fxP
'fxP     User_FX returns "String"
'fxP
'fxP     This function will find the NT/Win2000/Win 98 User ID
'fxP     Uses the API referenced by GetUserName
'fxP
'fxP     eg  yyy = User_FX
'fxP         will return the NT Username  ... to variable yyy
'fxP
'fx      Developed GR  Jan 2000
'fx      July 2002 SM  Modified to work on win 95
'fx      Based on Microsoft Knowledge Base Article - 152970
'fxP     --------------------------------------------------------


On Error Resume Next

Dim lSize As Long
Dim lpstrBuffer As String, trimStr As String
lSize = 255
lpstrBuffer = Space$(lSize)
If GetUserName(lpstrBuffer, lSize) Then
  User_FX = left$(lpstrBuffer, lSize - 1)
Else
  User_FX = "Unknown"
End If

End Function
Then on the BeforeInsert & BeforeUpdate events you can list the code as:
Code:
Me.WhoCreated = User_FX
Me.WhoModifies = User_FX
Regards,
Laura

FYI...My user id has changed. My old id was lbreitenbach

The only thing standing between you and your goal is doubt. Quit doubting yourself and you'll be able to accomplish anything!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Session ID swapping from user to user... greenwar VS.NET 2002/2003 3 September 7th, 2007 08:44 AM
Solution to the Strange User File entries Wolven BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 2 April 24th, 2007 07:40 PM
Strange User File entries... Wolven BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 5 April 23rd, 2007 02:32 AM
Simultaneous Entries (locking data) needelp Access VBA 2 September 15th, 2006 11:09 AM
how to execute the cursor for online data entries madhuri.sirsat SQL Server 2000 2 April 13th, 2005 11:03 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.