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!

execute a sql server stored procedure from ms access database

Status
Not open for further replies.

timfost

Programmer
May 8, 2006
11
CA
folks, is it possible to execute a stored procedure in the sql server database from an ms access database. We already have the stored procedure running via a sql server job but the users want to be able to execute it on demand and already use ms access to query tables in the database.

thanks
 
You can use an ADO Command object to execute stored procedures on SQL Server.

 
Also do a help search on pass-through queries.

When everything is coming your way, you're in the wrong lane.
 
thanks folks. I'll try the pass through query as it looks like it may work according to the help documents. I'm not familiar with access or vb so couldn't really find any good examples of an ado command object. JoeAtWork, do you have any links to some examples of how to use it?
 
Here's the first example I could find from an old project. This runs the stored procedure "GetAllPlantCartonRecords". It should be noted that the MakeDatabaseConnection() function returns an ADO connection object that has opened a connection with the database.

If you Google "ADO Command Object" you should be overwhelmed with information.

Code:
'Created:       11-Dec-2001
'
'Description:   Returns a recordset of all undeleted Plant Carton records, all fields
Public Function GetAllPlantCartonRecords() As ADODB.Recordset
    Dim objCommand As ADODB.Command
    
    Set objCommand = New ADODB.Command
    objCommand.ActiveConnection = MakeDatabaseConnection
    objCommand.CommandText = "GetAllPlantCartonRecords"
    objCommand.CommandType = adCmdStoredProc
    
    Set GetAllPlantCartonRecords = objCommand.Execute
    
    Set objCommand = Nothing
End Function

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top