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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I execute a SQL Server Stored Procedure from Access?

Vba questions

How do I execute a SQL Server Stored Procedure from Access?

by  jmeadows7  Posted    (Edited  )
Use the following code to call a stored procedure - the example takes two parameters from my form:
The strConnect is a constant in the form of:
"ODBC;DSN=YOUR_DSN_NAME;SRVR=YOUR_SERVER_NAME;DATABASE=YOUR_DB_NAME;UID=youruserid;PWD=youruseridpassword;"

Dim strConnect As String
Dim strSQL As String
Dim dbs As Database
Dim qdf As QueryDef
Dim strErrMsg As String

Set dbs = CurrentDb

strConnect = c_CONN_STR

Set qdf = dbs.CreateQueryDef("")
qdf.Connect = strConnect
strSQL = "exec cssp030_Completed_Daily_Updates " & Me![txtsw010_Loc_Id] & ",'" & Me![txtsw010_Retrieve_Date] & "', " & "'" & Forms![frm000_Main]![txtW000_User_ID] & "'"
qdf.ReturnsRecords = False
qdf.SQL = strSQL
dbs.QueryTimeout = 2000 'Set timeout to 4 minutes so it doesn't timeout.
qdf.ODBCTimeout = 1000
qdf.Execute
DoCmd.Hourglass False
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top