2 days ago: Power and Internet are out in my office due to Hurricane Ian. Click for details.
 
Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   Seminars   Templates   TechHelp   Fast Tips   Forums   Help   Contact   Join   Order   Logon  
 
Home > Forums > Access
Access Forum


Back to Access Forum
 

TempVars Upload Images   Link  
Tom Kelly 
12 days 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
12 days ago
Environ
Tom Kelly
12 days ago
Thank you for the resources!  I'll be doing some digging into those :-)
Kevin Yip
12 days 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
11 days 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
11 days 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
6 days ago
Just be careful because environment variables can be overwritten by someone who has mad hacker skillz. LOL
Add a ReplyUpload an Image


Back to Access Forum Comments
 

Start a NEW Conversation
 
Only students may post right now. Click here for more information on how you can set up an account. If you are a student, please LOG ON first.
 
Subscribe
 

Check out these other pages that may be of interest to you:

9/27/2022Report Border
9/26/2022First Day of Month
9/23/2022Before Update
9/22/2022Synchronize Subforms
9/21/2022InputBox
9/20/2022Link Master Fields
9/19/2022DateSerial
9/18/2022Sequential Annual Coding
9/16/2022Scope
9/15/2022Resize Forms
 
 

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
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
Email Richard
Mailing Address
Phone Number
Fax Number
Course Survey
Blog RSS Feed    Twitter

YouTube Channel    LinkedIn