473,401 Members | 2,125 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

executing query from code

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
2 1487
jaxjagfan
254 Expert 100+
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
That is perfect, the Dlookup worked like a charm. The answer was so simple that it was eluding me.

Marc
Feb 1 '08 #3

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

Similar topics

14
by: Jay O'Connor | last post by:
Is there a good way to import python files without executing their content? I'm trying some relfection based stuff and I want to be able to import a module dynamically to check it's contents...
7
by: Rick Caborn | last post by:
Does anyone know of a way to execute sql code from a dynamically built text field? Before beginning, let me state that I know this db architecture is built solely for frustration and I hope to...
0
by: tukaram.thatikonda | last post by:
Hi Guys, I have written a small windows application in VB.Net to test ADO.Net performance while executing long running query. The query works most of the time but fails sometime. I am trying...
10
by: Heiko Pliefke | last post by:
Hi NG! I wrote a stored procedure which at first deletes 100.000 rows and then inserts 100.000 new rows. There is a huge difference between executing this SP in the query-analyzer (runtime...
20
by: Neil Robbins | last post by:
I am trying to execute a make table query in my vb.net program. The db that I am accessing is an Access 2000 format db. The SQL code that I am using has been cut and pasted from the SQL View having...
2
by: chets | last post by:
Hi All, I am facing problem in executing one dynamic query in PRO *C program on linux. I want to update table mytable by data MADURAI for a column mycolumn1 where primary key is myPK.I want to...
8
by: Daz | last post by:
Hi everyone. I was faced with the choice of whether my problem is indeed a PHP problem or a MySQL. I have decided it's a PHP problem as I don't experience the same problem when I execute the...
1
by: jesmi | last post by:
my code is: U]employee.cfm <html> <head> <title>Employee List</title> </head> <body> <h1>Employee List</h1>
7
by: wingsss | last post by:
i am currently using WindowsXP SP2 all updated apache 2.2.4 PHP 5.2.3 MySQL 5.0 and apache hang up when running this code //...
5
by: rickbytes | last post by:
Hello, Is there a way to make my vb code to wait for a mysql query to finish executing before trying to run a new query? For example: Is there a way I can run a CREATE TEMPORARY TABLE _mytable...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.