Solved

vba code to capture the user's sql login name

Posted on 2011-02-21
10
506 Views
Last Modified: 2013-11-27
I want to be able to capture and display the user's sql login name on my form when the user checks a checkbox called "InvestigationComplete" on my form.  Is there a way to accomplish this programatically.  I have admin writes to Microsoft SQL server.  The datasource is "ucrdata" sql table with a field called TestTech that I want to capture this login name.
Private Sub InvestigationComplete_Click()
Me.InvestigationComplete.Value = -1
Me.InvestigationComplete.Locked = True
Me.TestTech.SetFocus
me.TestTech.Value = ............user's sql login ID............
End Sub

Open in new window

0
Comment
Question by:sxxgupta
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
10 Comments
 
LVL 45

Expert Comment

by:aikimark
ID: 34947218
are you not using the Windows login for authentication?
0
 

Author Comment

by:sxxgupta
ID: 34947232
No, our IT group is not using this option as users may have the same generic windows login name (BTW...I am not in IT but in quality engineering)
0
 
LVL 5

Expert Comment

by:roger_karam
ID: 34947617
Hello. From what I've read, user for SQL Server is SYSTEM_USER.
You are however in a MS Access section...
0
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 

Author Comment

by:sxxgupta
ID: 34947915
yes??
0
 

Author Comment

by:sxxgupta
ID: 34947917
again, how do I use vba code to capture the sql login id of a user?
0
 
LVL 5

Expert Comment

by:roger_karam
ID: 34948125
Sorry, I guess what I meant to say is: where are you applying this code? in a VB accessing a SQL Server from excel?
0
 

Author Comment

by:sxxgupta
ID: 34948159
sorry for not clarifying

vba code accessing a sql server from Microsoft Access (version 2002) form.
0
 
LVL 5

Accepted Solution

by:
roger_karam earned 500 total points
ID: 34948179
Ah... well, I think that's been done. Try adding the funcion from Jalcadmim (http://www.experts-exchange.com/Microsoft/Development/MS_Access/Access_Coding-Macros/Q_23630570.html)

me.TestTech.Value = GetSqlUser()


Function GetSqlUser() As String
Dim qrd As DAO.QueryDef, rst As DAO.Recordset

Set qrd = CurrentDb.CreateQueryDef("")
With qrd
.Connect = CurrentDb.TableDefs(0).Connect
.SQL = "SELECT SYSTEM_USER"
.ReturnsRecords = True
End With

Set rst = qrd.OpenRecordset()
GetSqlUser = rst(0).Value

rst.Close
Set rst = Nothing
Set qrd = Nothing
End Function
0
 

Author Closing Comment

by:sxxgupta
ID: 34951215
Awesome!!!!!!!!!  Thanks Roger:)
0
 
LVL 5

Expert Comment

by:roger_karam
ID: 34954506
Thanks for the points sxxqupta!

Glad I could help, but credit goes to jalcadmin for the solution!

-RK
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

739 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