Limit Query to Current User Name

M

Mark

I'm trying to build a query that will report production stats for system
users, but I'd like to limit the results to the current user. The username
is a field in the data, so I can query on it. But, is there a way to include
the current username is the query conditions without the user having to enter
it? I want for them to only see their own stats, not their team mates. I'm
sure it can be done; anybody know how?
Thanks in advance!
Mark
 
M

MGFoster

Mark said:
I'm trying to build a query that will report production stats for system
users, but I'd like to limit the results to the current user. The username
is a field in the data, so I can query on it. But, is there a way to include
the current username is the query conditions without the user having to enter
it? I want for them to only see their own stats, not their team mates. I'm
sure it can be done; anybody know how?
Thanks in advance!
Mark

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

If you set up User Security (unavailable in Access 2007?) you can use
the CurrentUser() function:

WHERE username = CurrentUser()

Read the SecFAQ to get info on how to set up User Security. Just Google
for "Access SeqFAQ."

HTH,
--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)
** Respond only to this newsgroup. I DO NOT respond to emails **

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBSsei94echKqOuFEgEQKnxACglFj3+qfXLZULGttEkFqfGEz1+nEAoJMM
22GPWQSgXoZoWXOqlaeu2y8N
=5N8u
-----END PGP SIGNATURE-----
 
M

Mark

Yep, I'm querying from Access. I copied that code into a new module. I've
never created or used a module. How do I call it in my query?
 
D

Douglas J. Steele

Your query would be something like

SELECT Field1, Field2, Field3
FROM MyTable
WHERE UserID = fOSUserName()

Incidentally, if you're not used to code, make sure you didn't name the
module fOSUserName: modules cannot have the same name as functions or subs
contained within them.
 
M

Mark

Thank You!!! That worked. Thanks for clarifying about the module name. I
had indeed given it the same name as the function. Thanks for your help. I
appreciate it BIG Time.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top