Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Access Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
TempVars
Tom Kelly 
    
4 years ago
Greetings Experts and Veterans ... newbie here that knows next to nothing except what I learned from Computer Learning Zone and Richard Rost! Well a few other YouTube videos as well 😉 😉
A little background ... I have a pretty decent and simple data base. My relationships are connected well ... I have primary keys and associated foreign keys in my tables and the data is getting into the fields the way it's supposed to through some forms I designed.
I created a Login Form that opens to my Main Menu.  My Main Menu has a couple of command buttons to open up different forms. One button opens up "Individuals List" and a button to open up my Individual Person Form which has the different fields and all is great!  On that Individual Person Form I have a Command Button to "set an appointment" for that individual person.
When I click on "Set Appointment" it opens my AppointmentForm which has the following fields: UserName (the Staff person that currently logged into the database), Individual (first name, last name), StartDateTime (start of appointment), EndDateTime (end of appointment - auto set for an hour after the start of the appointment), Title, and Notes!
My question:  How can I get UserName field to be automatically populated with the User's "username".
Ex: I log into the computer and navigate to set an appointment for Bill Smith.  When I get to my AppointmentF I am able to automatically populate the "Bill Smith" from the Individual Person form BUT how can I set "TomK" into the User field.  Presently it's a Combo Box and I can drop down to find the User but it would be nice if I could have my name (or the name of whoever is signed in automatically pop into that field)!!
Thank you in advance!
Alex Hedley  @Reply  
           
4 years ago
Alex Hedley  @Reply  
           
4 years ago
Tom Kelly OP  @Reply  
    
4 years ago
Thank you for the resources!  I'll be doing some digging into those :-)
Kevin Yip  @Reply  
     
4 years ago
If it is the Windows login user name you want, you need to have VBA call a function from a Windows DLL.  It's an advanced topic and I don't know if any of Richard's videos cover that.  You may want to try the following code.  This is what I use when I need my Windows login name in Access.  The function GetUserNameT() below will return your Windows user name:

Option Compare Database
Option Explicit

Declare Function GetUserName& Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long)

Function GetUserNameT()
    Dim s As String, cnt As Long, dl As Long
    cnt = 199
    s = String(200, 0)
    dl = GetUserName(s, cnt)
    GetUserNameT = Left(s, cnt - 1)
End Function

' P.S. String(200,0) above creates a string of two hundred null characters, as required by the next line.
Tom Kelly OP  @Reply  
    
4 years ago
Thank you Kevin!! I will try that. Doesn't "Environ("UserName") do the same thing when it comes to finding the UserName of the person signed on or logged into the computer?  Also if that is the case how can I use a Msgbox command to see if the code does in deed catch the right "UserName".  
In your code would ... MsgBox GetUserNameT ... before End Function show me who's signed in?
Kevin Yip  @Reply  
     
4 years ago
You're right, Environ("username") does the same thing.  In fact, this and GetUserNameT are one and the same; they look through the environment variables for the user name.  GetUserNameT is the old version, and Environ() is built into later versions of Access.

You can assign the return value of Environ("username") or GetUserNameT() to a string variable, say, username.  Then you can display it or check its value as you see fit.
Richard Rost  @Reply  
          
4 years ago
Just be careful because environment variables can be overwritten by someone who has mad hacker skillz. LOL

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Forum.
 

Next Unseen

 
New Feature: Comment Live View
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 4/30/2026 7:08:38 AM. PLT: 1s