Calling stored procedure using VBA

前端 未结 2 926
半阙折子戏
半阙折子戏 2020-12-01 13:18

I am working in Access 2010 user front-end with a Microsoft SQL Server 2008 back-end.

The tables in Access are all linked to the SQL server database.

I have

2条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-01 13:41

    Victoria,

    You can run a stored procedure using ADO, like below...

    Set mobjConn = New ADODB.Connection
    mobjConn.Open "your connection string"
    Set mobjCmd = New ADODB.Command
    With mobjCmd
        .ActiveConnection = mobjConn 
        .CommandText = "your stored procedure"
        .CommandType = adCmdStoredProc
        .CommandTimeout = 0
        .Parameters.Append .CreateParameter("your parameter name", adInteger, adParamInput, , your parameter value)
        ' repeat as many times as you have parameters
    
        .Execute
    End With
    

    To get your connection string, you can use the line

    Debug.Print CurrentDb.TableDefs("tblInstrumentInterfaceLog").Connect
    

    in the Immediate Window and that should show you a connection string which you can use.

    Would you try that and let me know if you have any problems.

    Ash

提交回复
热议问题