showing database username on Access form (adp)

  • Thread starter Thread starter Ron Heusdens
  • Start date Start date
R

Ron Heusdens

Hi,

I am using access2003 frontend with sql2000 database (adp).
Most of the logic is implemented in stored procs.
What i want to achieve is to show the name of the database user on an access
form (e.g. 'sa')
(pretty much the result of a 'SELECT USER').
Can this be done without storing the data first in a (temporary) table?
Using Dlookup didn' t work so far...

Any help is appreciated.
Grtx,Ron
 
Ron said:
I am using access2003 frontend with sql2000 database (adp).
Most of the logic is implemented in stored procs.
What i want to achieve is to show the name of the database user on an access
form (e.g. 'sa')
(pretty much the result of a 'SELECT USER').
Can this be done without storing the data first in a (temporary) table?
Using Dlookup didn' t work so far...

What do you want to do with that temporary table?

Well, anyway, you can solve your problem with a few lines of VBA and
without any temp-tables:

Dim rs As ADODB.Recordset
Const strSQL As String = "SELECT SUser_SName()"

Set rs = CurrentProject.Connection.Execute(strSQL)
Forms("YourForm")!YourControl = rs.Fields(0).Value

rs.Close
Set rs = Nothing


Cheers
Phil
 
why a const for the sql statement; is that faster??

less memory?

No, none of the two.

While writing the code I made the assumption that strSQL will
never change. By using a const I made this assumption clear
to any reader of the code and even better I made the compiler
enforce my assumption.

With short code like that sample, especially as the const is
only used once, this may not make much sense, but in longer
and more complex routines I consider beeing as explicit as
possible to be good programming practice.

Cheers
Phil
 
Back
Top