Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Example Please

Status
Not open for further replies.

RicRom

Programmer
Jun 9, 2004
6
NL
Hi Guys (And girls)

I managed to execute a stored procedure from within a access project (Wow!!).. but how can I do something simple, lets say make a textbox filled with the username..?
I have the following SP:

CREATE PROCEDURE DBO.GEBRUIKER AS
SELECT SESSION_USER as GEBRUIKER
RETURN

How can I set in a access project a textbox to the result of this SP ??

Thanks

Richard
 
You can use a Function to return a value to a textbox.
=ReturnUser()


Public Function ReturnUser() As String

Dim cn As New ADODB.Connection, sql1 As String
Dim rs As New ADODB.Recordset, connString

'Set cn = CurrentProject.Connection
'- current connection of ADP
'--- connect to sql server if not current connection.
connString = "provider=SQLOLEDB.1;" & _
"User ID=sa;Initial Catalog=northwind;" & _
"Data Source=bigtuna;" & _
"Persist Security Info=False"
cn.ConnectionString = connString
cn.Open connString

sql1 = " Select suser_sname() "
Set rs.ActiveConnection = cn
rs.Open sql1, cn, adOpenKeyset, adLockReadOnly
Debug.Print "return = "; rs(0)

ReturnUser = rs(0)
rs.Close
Set rs = Nothing
End Function
 
Hey cmmrfrds,

Works like a charm!
Thanks

Richard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top