Results 1 to 11 of 11
  1. #1
    netchie is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Aug 2010
    Posts
    92

    Unhappy Automatic Username On Data Entry

    Hi,



    Ok, so what I am aiming for is to automatically pop-up the username of the person who is adding data into the database. I created a table "tblCurrentlyLoggedIn" and Field Name is "empCurrentlyLoggedIn". For my Data Entry button, I put this:

    Private Sub Form_Close()
    DoCmd.SetWarnings False
    DoCmd.RunSQL "DELETE * FROM tblCurrentlyLoggedIn WHERE empCurrentlyLoggedIn = fOSUserName()"
    DoCmd.SetWarnings True
    'Application.CompactRepair Application.CurrentDb.Name, Application.CurrentDb.Name
    End Sub


    Private Sub Form_Open(Cancel As Integer)
    DoCmd.SetWarnings False
    DoCmd.RunSQL "INSERT INTO tblCurrentlyLoggedIn ( empCurrentlyLoggedIn ) " & _
    "SELECT fOSUserName() AS Users;"
    DoCmd.SetWarnings True
    End Sub

    When I tested it and clicked the Data Entry button, I got an error message "Run time error '3085': Undefined function 'fOSUserName' in expression. What did I miss?

  2. #2
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Did you add the function to a standard module?

    http://access.mvps.org/access/api/api0008.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    netchie is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Aug 2010
    Posts
    92
    Sorry pbaldy... access dummy here lol. What do you mean by standard module?

    Ok, I deleted the program that I posted before and copied the program you gave me and paste it to Event Procedure of my Data Entry button. I tried it and I got an error message saying "The expression On Click you entered as the event property setting produced the . error: Only comments may appear after End Sub, End Dunction, or End Property. The expression may not result in the name of macro, the name of a user-defined function, or [Event Procedure]. There may have been an error evaluating the function, event, or macro.

  4. #4
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    A standard module is not behind a form or report. Insert/Module in the VBA window. Make sure not to name it the same as the function.

    As to your error, it sounds like you got something outside the bounds of Begin Sub and End Sub. Hard to say exactly without seeing it.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    netchie is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Aug 2010
    Posts
    92
    I put back the old program that I had before and found a way to create a module and pasted the one that you gave me. I tested it, I clicked the data entry button and yes there is no error message anymore BUT how come the username field is still blank?

  6. #6
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Can you post the db here?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    It worked fine for me. If I open the applicable form, my name is added to the table. When I close it, it's deleted from the table.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  8. #8
    netchie is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Aug 2010
    Posts
    92
    Not for me; I clicked the main menu for new entry, clicked New button and entered data. After I saved it, I went to the its table and everything I entered were saved including DateOccurred except username. Please see atached.

  9. #9
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    That must be some other process. The one on this thread populates a single field called empCurrentlyLoggedIn. That is the only field in that table.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  10. #10
    netchie is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Aug 2010
    Posts
    92
    Ok, thanks for your help

    Have a great day.

  11. #11
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    No problem. I'll keep an eye out for your other threads on the topics in your email.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 14
    Last Post: 08-17-2015, 02:32 AM
  2. Automatic Recurring Entry
    By Al77 in forum Access
    Replies: 3
    Last Post: 02-15-2012, 04:24 PM
  3. Automatic Field DAta Entry
    By Lupson2011 in forum Access
    Replies: 4
    Last Post: 09-01-2011, 09:15 AM
  4. Access 2003 automatic field entry
    By RANCHLAW56 in forum Forms
    Replies: 6
    Last Post: 12-30-2010, 02:57 PM
  5. Automatic Data Entry on a Specific Date
    By alanbrai in forum Programming
    Replies: 2
    Last Post: 11-14-2007, 05:15 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums