I am working in Access 2010 with a Microsoft SQL Server 2008 backend. I have a stored procedure that inserts new values(supplied by the parameters) into a table. The value
Use a saved pass-though query.
You code then becomes:
With currentdb.querydefs("MyPass")
.sql = "exec StoreProcName " & strBach & “,” & strInstrmentName
.execute
End With
So, you only need two lines of code here. You don't even have to declare any connection strings or even any variables if you use a saved pass-through query.
Dim conn As ADODB.Connection
Dim cmd As ADODB.Command
Set conn = New ADODB.Connection
conn.ConnectionString = “your connection String here”
conn.Open
Set cmd = New ADODB.Command
cmd.ActiveConnection = conn
cmd.CommandType = adCmdStoredProc
cmd.CommandText = "upInsertToInstrumentInterfaceLog"
cmd.parameters.Append cmd.CreateParameter("@BatchID", adVarChar, adParamInput, 60, "value for BatchID")
cmd.parameters.Append cmd.CreateParameter("@InstrumentName", adVarChar, adParamInput, 60, "value for InstrumentName")
'...
cmd.Execute
conn.Close