Looking for an alternative to Access's Environ("username") for SQL Server.

Posted on 2006-04-06
Last Modified: 2008-02-01
I've just up-sized a .mdb application to a 2000 SQL server.  Everything worked great except I've used    Environ("username")   in several default and SQL queries.   Apparently SQL does not like Environ("username")  and I got ODBC errors.  I got around the default problem but I have not found a solution to include Environ("username") in a SQL query.  Any Ideas?

Question by:WorthN
    LVL 39

    Accepted Solution

    Create a public function in a global module and call the function from within the query:
    Public Function GetEnviron(EnvironCall As String)
       GetEnviron = Environ(EnvironCall)
    End Function

    Call with:

    Author Comment

    That worked for the query, but is very slow for some reason when used on an access form.  Got better speed using a mix of the two.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    In the article entitled Working with Objects – Part 1 (, you learned the basics of working with objects, properties, methods, and events. In Work…
    Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
    In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
    In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now