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

How can you tell if a user is logging in using Access

anoble1
100+
P: 223
I am trying to set up my databases to where I can tell who is logged in. I really don't have a good idea of how to do it. Right now I do have a Rights table with all the users in it. I just added a column which is either on or off called (SingnedIn)

I am trying to figure out how; whenever a user pulls my database up, it will put change the "signedIn" field to True for that user. I have made a hidden box on the main screen that grabs the users NTID name. I just need a little help on how to tie that to the tableRights.

Can anyone help?
Thanks
May 10 '10 #1

✓ answered by TheSmileyCoder

Use a hidden(Visible=false) form frm_Startup, where you have the following code, and set the form to open at startup.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2.   'Set user status=Logged in
  3.   Dim strSQL as String
  4.   strSQL="Update tbl_Users SET SingnedIn=TRUE WHERE tx_UserInitials='" & Environ("UserName") & "'"
  5.   Docmd.SetWarnings false
  6.     Docmd.RunSQL strSQL
  7.   Docmd.setwarnings True
  8.  
  9.   'Now open the form you want user to see when he opens the database
  10.   Docmd.OpenForm "frm_Menu"
  11. End Sub
And in the same form, add code to the forms Close event,

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Close()
  2.   'Set user status=Logged out
  3.   Dim strSQL as String
  4.   strSQL="Update tbl_Users SET SingnedIn=FALSE WHERE tx_UserInitials='" & Environ("UserName") & "'"
  5.   Docmd.SetWarnings false
  6.     Docmd.RunSQL strSQL
  7.   Docmd.setwarnings True
  8.  
  9. End Sub

Share this Question
Share on Google+
9 Replies


TheSmileyCoder
Expert Mod 100+
P: 2,321
Use a hidden(Visible=false) form frm_Startup, where you have the following code, and set the form to open at startup.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2.   'Set user status=Logged in
  3.   Dim strSQL as String
  4.   strSQL="Update tbl_Users SET SingnedIn=TRUE WHERE tx_UserInitials='" & Environ("UserName") & "'"
  5.   Docmd.SetWarnings false
  6.     Docmd.RunSQL strSQL
  7.   Docmd.setwarnings True
  8.  
  9.   'Now open the form you want user to see when he opens the database
  10.   Docmd.OpenForm "frm_Menu"
  11. End Sub
And in the same form, add code to the forms Close event,

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Close()
  2.   'Set user status=Logged out
  3.   Dim strSQL as String
  4.   strSQL="Update tbl_Users SET SingnedIn=FALSE WHERE tx_UserInitials='" & Environ("UserName") & "'"
  5.   Docmd.SetWarnings false
  6.     Docmd.RunSQL strSQL
  7.   Docmd.setwarnings True
  8.  
  9. End Sub
May 10 '10 #2

anoble1
100+
P: 223
@TheSmileyOne
Ok, here is my code. it looks right to me.

I am getting an error message when I open the database. It throws up the SignedIn with a textbox. Then it says "Cannot update 'SignedIn'; field not updateable.

Expand|Select|Wrap|Line Numbers
  1.    'Set user status=Logged in
  2. Dim strSQL As String
  3. strSQL = "UPDATE tblReviewNames SET SingnedIn = True WHERE (((tblReviewNames.NTID)='" & Environ("UserName") & "'));"
  4. DoCmd.SetWarnings False
  5.    DoCmd.RunSQL strSQL
  6. DoCmd.SetWarnings True
May 10 '10 #3

NeoPa
Expert Mod 15k+
P: 31,186
Whenever a user logs in add their name (ID) to your table. On closing the database have an event routine that removes it. If it is possible for a user to be on multiple times at once then include station (PC) details in the record.
May 10 '10 #4

anoble1
100+
P: 223
@anoble1
Got it to work! Works great! I messed up the query but works perfect now.
May 10 '10 #5

NeoPa
Expert Mod 15k+
P: 31,186
Environment variables are fine up to a point, but they are not very secure, as anyone can change this to reflect a different user name after logging in. See Retrieve User ID for a more secure method.
May 10 '10 #6

P: 15
If you want to see who's actually in a database at any given time and when they go in and out of the database, you may want to take a look at purchasing a predesigned package to do that.
May 11 '10 #7

NeoPa
Expert Mod 15k+
P: 31,186
I expect a package, especially one you have to pay for, would be overkill for such a simple situation. This is not rocket science.
May 11 '10 #8

P: 15
if you need to handle connections to the database that's outside your application, it's not such a trivial problem. You'll need something to monitor it independent of your application.
May 17 '10 #9

NeoPa
Expert Mod 15k+
P: 31,186
I don't believe that to be true. Is there anything that could support that contention? Especially bearing in mind that a viable solution has apparently been found to work?
Feb 11 '12 #10

Post your reply

Sign in to post your reply or Sign up for a free account.