Results 1 to 9 of 9
  1. #1
    SAM75 is offline Novice
    Windows 7 32bit Access 2013 32bit
    Join Date
    Nov 2017
    Posts
    7

    Exclamation How to store login ID in a table field

    Dear all


    I'm working on a simple database which collects activity data from my sub-worker colleagues. I have designed a simple Login form (Image bellow):


    Click image for larger version. 

Name:	001.png 
Views:	29 
Size:	71.7 KB 
ID:	33560

    And I want to store the User LoginID in a table as image bellow automatically.




    Click image for larger version. 

Name:	002.png 
Views:	29 
Size:	96.8 KB 
ID:	33561

  2. #2
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,933
    various ways to do it. But in principle, when your user logs in, store the login ID in a global variable in a module. then in your forms in the form before update event, assign the global variable value to the userid field.

  3. #3
    SAM75 is offline Novice
    Windows 7 32bit Access 2013 32bit
    Join Date
    Nov 2017
    Posts
    7
    Sorry. Would you please explain in a sample?

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Another approach is to store the login ID in a textbox on a form that never closes, such as a MainMenu. Then code references the textbox to get the ID. I use this approach because global variables lose their value when runtime errors occur. Control's DefaultValue property can even reference the textbox on MainMenu to autopopulate.

    And even another approach is to use a TempVar to hold the ID. They don't lose value. I have never used TempVar.

    A global variable is declared in a general module header then code in another module (the login form) sets the variable value. More code in your data entry form module references the variable to populate field. Bing: Access global variable. Here is one http://www.blueclaw-db.com/access_da...l_variable.htm
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    SAM75 is offline Novice
    Windows 7 32bit Access 2013 32bit
    Join Date
    Nov 2017
    Posts
    7
    Quote Originally Posted by June7 View Post
    Another approach is to store the login ID in a textbox on a form that never closes, such as a MainMenu. Then code references the textbox to get the ID. I use this approach because global variables lose their value when runtime errors occur. Control's DefaultValue property can even reference the textbox on MainMenu to autopopulate.

    And even another approach is to use a TempVar to hold the ID. They don't lose value. I have never used TempVar.

    A global variable is declared in a general module header then code in another module (the login form) sets the variable value. More code in your data entry form module references the variable to populate field. Bing: Access global variable. Here is one http://www.blueclaw-db.com/access_da...l_variable.htm
    I used the TempVar to store current User ID in a text box. Thank you. Now I need to refer a table field to read this value from my form textbox. The form that contains textbox is "frmLogin", the textbox is "text17", the table Which I need to store the textbox value is "tbl_rec_reg" and the field name is "logger".

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    As Ajax indicated, use code in form BeforeUpdate event to populate field of new record (or alternatively, use DefaultValue property and no code needed).

    However, your image shows a table with existing records. If you want to populate all those records with the same value, then run an UPDATE query.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    SAM75 is offline Novice
    Windows 7 32bit Access 2013 32bit
    Join Date
    Nov 2017
    Posts
    7
    Quote Originally Posted by June7 View Post
    As Ajax indicated, use code in form BeforeUpdate event to populate field of new record (or alternatively, use DefaultValue property and no code needed).

    However, your image shows a table with existing records. If you want to populate all those records with the same value, then run an UPDATE query.
    Thank you very much. "TempVar" worked fine as below. But when I tried to fill the current date and time along with logger, it doesn't work and says there's a syntax error:

    Click image for larger version. 

Name:	003.png 
Views:	24 
Size:	5.2 KB 
ID:	33565

    Also, Each time I log in db, this message appears:


    Click image for larger version. 

Name:	004.png 
Views:	23 
Size:	120.1 KB 
ID:	33566


    And a new record is created in the log table as below. But I want to replace the new logger ID with the previous one and have just one record

    Click image for larger version. 

Name:	005.png 
Views:	23 
Size:	30.0 KB 
ID:	33567

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Date is a reserved word. Should not used reserved words as names for anything. If you do, enclose in [ ]: [date].

    Don't understand issue. INSERT sql inserts a new record. If you want to edit existing record then use UPDATE sql.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  9. #9
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    Did anyone else notice that we're dealing with either a lookup or multi-value field here?
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

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

Similar Threads

  1. Checkbox to store into Table Field
    By sud2017 in forum Forms
    Replies: 10
    Last Post: 11-15-2017, 01:33 PM
  2. Store an IIF option is a table field
    By archie1_za in forum Database Design
    Replies: 10
    Last Post: 11-01-2017, 06:54 AM
  3. Control to get login but store id to table
    By nmart1230 in forum Forms
    Replies: 57
    Last Post: 11-19-2014, 08:29 PM
  4. Replies: 7
    Last Post: 11-03-2012, 06:17 PM
  5. Replies: 0
    Last Post: 09-25-2006, 03:42 AM

Tags for this Thread

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