开发者

Access Project: Automatically Pass Parameters to Run Store Procedure Button

开发者 https://www.devze.com 2022-12-19 08:26 出处:网络
In an Access Project (ADP file ONLY) in Access 2007, how do I automatically pass parameters to a stored procedure when the stored procedure is called by clicking a button?The wizard allowed me to link

In an Access Project (ADP file ONLY) in Access 2007, how do I automatically pass parameters to a stored procedure when the stored procedure is called by clicking a button? The wizard allowed me to link a stored procedure to a button, but clicking the button prompts users for the parameters. I want to pass properties of the current record to the stored proced开发者_运维知识库ure and I don't see a way to do it. Maybe I need to wire this up somehow in the properties of the On Click event, but I don't see hwo to do it.


The solution appears to be to modify the On Click event to the following:

DoCmd.RunSQL ("EXEC StoredProcedureName @ParameterName=" & FieldName)

This resolved my issue. This can be simplified to the following:

DoCmd.RunSQL ("EXEC StoredProcedureName " & FieldName)

I also found it was helpful to declare a string and build the SQL string that I wanted to execute separately. So here's what I really used:

Dim strSqlCode As String
strSqlCode = "EXEC StoredProcedureName " & FieldName1 & ", " & FieldName2 & ", " FieldName3
DoCmd.RunSQL (strSqlCode)

Simple and to the point.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号