Results 1 to 13 of 13
  1. #1
    Join Date
    May 2009
    Location
    Crete, Greece
    Posts
    90

    Unanswered: Identify user on form

    I need to have a field on my form which shows which particular user created the record, and another field which shows who received the payment. Ideally this should be an automatic function, (probably an 'AfterUpdate' event on the field) which would mean that users would have to log in at the start of an access session. Is the correct way to do this to assign security settings, and if so does anyone have any tips? The database doesn't really need security as such; only to fulfil this function.

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    best solution in my books is to use the API call to find the network logon
    you can use the currentuser() function bu that is easily spoofed.

    both approaches will fail if the user leaves their terminal unlocked when they are away from the address.

    getting the network logon in my books is preferable as it gets rid of the requirement of the user to logon when using your apps. its harder to spoof or work around. google dev ashish api or have a trawl through the code bank for the similar/same code posted by PKStormy
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Apr 2004
    Location
    Derbyshire, UK
    Posts
    789
    Provided Answers: 1
    Quote Originally Posted by LisaP
    I need to have a field on my form which shows which particular user created the record, and another field which shows who received the payment. Ideally this should be an automatic function, (probably an 'AfterUpdate' event on the field) which would mean that users would have to log in at the start of an access session. Is the correct way to do this to assign security settings, and if so does anyone have any tips? The database doesn't really need security as such; only to fulfil this function.
    Hi

    You could used th API Funtion to get the 'UserName', that is the user's Window login name as follows
    Code:
    Option Compare Database
    Option Explicit
    
    Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal IpBuffer As String, nSize As Long) As Long
    
    Function ThisUserName() As String
        Dim LngBufLen As Long
        Dim strUser As String
        
        strUser = String$(15, " ")
        LngBufLen = 15
        
        If GetUserName(strUser, LngBufLen) = 1 Then
            ThisUserName = Left(strUser, LngBufLen - 1)
        Else
            ThisUserName = "Unknown"
        End If
        
    End Function
    Don't know if that is what you mean, but you just then add somthing like this to the Form BeforeUpdate Event
    Code:
    If Me.NewRecord Then
        [CreatedBy] = ThisUserName  'Assign who entered data
        [CreatedDate] = Date      'Date created (if required)
    End If
    etc.

    Where, obviously [CreatedBy] and [CreatedDate] are the fields names to be populated.

    ?? MTB

    I guess I don't get any quicker answering questions!?

  4. #4
    Join Date
    May 2009
    Location
    Crete, Greece
    Posts
    90
    Thanks both. I'm a bit daunted by this, but I'll try it today and post again with the result.

  5. #5
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    no need to be daunted

    there's functions that will do the work for you

    "all" you need to do is to follow the instructions copy the code as specified and place the appropriate calls into your form/report whatever.

    if we don't push the boundaries now and then, then we ain't going to develop

    go for it, if things don't work out come back and we'll have another go to help you out.. its what dBForums does
    I'd rather be riding on the Tiger 800 or the Norton

  6. #6
    Join Date
    May 2009
    Location
    Crete, Greece
    Posts
    90
    Thank you for words of encouragement. I now have the moral strength to continue - just not the intellect!

    Will post back later today.

  7. #7
    Join Date
    May 2009
    Location
    Crete, Greece
    Posts
    90
    I'm finally ready to address this now. Where do I paste the API function code?

  8. #8
    Join Date
    Apr 2004
    Location
    Derbyshire, UK
    Posts
    789
    Provided Answers: 1
    Quote Originally Posted by LisaP
    I'm finally ready to address this now. Where do I paste the API function code?
    The API function declaration and UserName function shouid be pasted into a standard code module (not a form/class module)

    Good Luke!

    MTB

  9. #9
    Join Date
    May 2009
    Location
    Crete, Greece
    Posts
    90
    Going to need a bit more hand-holding than that, I'm afraid. Ok, I did right click on the form, clicked 'build event' and then pasted the code in the vb window. However, it's not working (surprise) and I'm guessing I put it in a 'form module', which is where you told me not to put it.

    um, so where does it go?

  10. #10
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    a code module
    as API: Get Login name suggests
    I'd rather be riding on the Tiger 800 or the Norton

  11. #11
    Join Date
    May 2009
    Location
    Crete, Greece
    Posts
    90
    It worked a dream! It was so easy - I would've saved myself a day's work if I had just got on and did it, rather being afraid of it. It also works lovely on my two subforms - I love it.

    Thank you so much healdeam and Mike The Bike.

  12. #12
    Join Date
    Apr 2004
    Location
    Derbyshire, UK
    Posts
    789
    Provided Answers: 1
    Quote Originally Posted by LisaP
    It worked a dream! It was so easy - I would've saved myself a day's work if I had just got on and did it, rather being afraid of it. It also works lovely on my two subforms - I love it.

    Thank you so much healdeam and Mike The Bike.
    So glad you got it working.

    Now you can do all sorts of things to prevent variouse people destroying your database!!

    MTB

  13. #13
    Join Date
    May 2009
    Location
    Crete, Greece
    Posts
    90
    Well, so far the major threat is me.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •