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

executing query from code

P: 3
I have done alot of research on this problem but I am unable to figure it out.

I have a table created with the following fields
ID
UserID (domain account)
UserName (full name of person)
UserRights(the user's rights)

to this table I have attached a query with a where clause on USERID
=Where Environ("username")

Basically when I run this query it will return the row for the current logged user.

Here is what I want to do.

On the first form to open I place some code that will run this query and then assign the string in UserName to a public variable and Assign the string in UserRights to a public variable.

The purpose of this is to have an "updated by" field in the main database that will display the full username. Also certain forms have administrator buttons that would be hidden to users that have UserRights set to "user"

This is going to be a shared database.

Thank you

Marc
Jan 29 '08 #1
Share this Question
Share on Google+
2 Replies


jaxjagfan
Expert 100+
P: 254
I have done alot of research on this problem but I am unable to figure it out.

I have a table created with the following fields
ID
UserID (domain account)
UserName (full name of person)
UserRights(the user's rights)

to this table I have attached a query with a where clause on USERID
=Where Environ("username")

Basically when I run this query it will return the row for the current logged user.

Here is what I want to do.

On the first form to open I place some code that will run this query and then assign the string in UserName to a public variable and Assign the string in UserRights to a public variable.

The purpose of this is to have an "updated by" field in the main database that will display the full username. Also certain forms have administrator buttons that would be hidden to users that have UserRights set to "user"

This is going to be a shared database.

Thank you

Marc
Here is a function that I use in a module and just call GetUserName():

Expand|Select|Wrap|Line Numbers
  1. Declare Function Win32GetUserName Lib "advapi32.dll" Alias "GetUserNameA" _
  2.     (ByVal lpBuffer As String, nSize As Long) As Long
  3.  
  4. Public Function GetUserName() As String
  5. 'requires system-call defined
  6. Dim lLen As Long, s As String, sText As String, lResult As Long
  7.  
  8. lLen = 255
  9. s = String$(lLen, 0)
  10. lResult = Win32GetUserName(s, lLen)
  11. If (1 = lResult) Then
  12.     sText = StringFromDLL(s)
  13. Else
  14.     sText = ""
  15. End If
  16. GetUserName = sText
  17. End Function
  18.  
  19.  
This function grabs the current user logged into the pc. You can set your variable to something like varUserID = GetUserName(). You could use a DLookup:
varUserName = DLookup("[UserName]","tblUsers", "[UserID]='" & GetUserName() & "'"
Or you can use the GetUserName function in your query and link to your users table to get the full name.
Jan 29 '08 #2

P: 3
That is perfect, the Dlookup worked like a charm. The answer was so simple that it was eluding me.

Marc
Feb 1 '08 #3

Post your reply

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