Call Stored Procedure from MS Access 2003
I shall contribute as well. I'm not a big programmer, but this is what I got and it works for me
......
I create a separate module like this:
Option Compare Database
Public ConnSQL As New ADODB.Connection
Public Sub Conn_SQLServer()
Dim strSQL As String
On Error GoTo Error_Handler
If ConnSQL.State = 1 Then Exit Sub 'if connection already on, then exit
With ConnSQL
.ConnectionString = "PROVIDER=MSDASQL;DRIVER={SQL Server};SERVER=Server_Name;DATABASE=DB_Name;TRUSTED_CONNECTION=Yes;"
.CursorLocation = adUseServer
.Open
End With
Exit Sub
Error_Handler:
MsgBox "Unable to connect to SQL Server." & "Error " & Err.Number & " - " & Err.Description & ", " & Err.Source, vbExclamation
End Sub
Then I call it where ever I need an Sproc ran....
Public Sub RunMonthly()
Dim recSQL As New ADODB.Recordset
Dim strSQL As String
Call Conn_SQLServer
On Error GoTo Err_Handler
strSQL = "EXEC S_Lookup_Locus '{TDate}'"
strSQL = Replace(strSQL, "{TDate}", Format(dteBeginDate, "Short date"))
ConnSQL.CommandTimeout = 0 'Prevents timeout error
Set recSQL = ConnSQL.Execute(strSQL)
If recSQL.State = 1 Then recSQL.Close
Exit Sub
Err_Handler:
MsgBox Err.Number & " " & Err.Description & " " & Err.Source
Exit Sub