Consulting

Results 1 to 3 of 3

Thread: How to call a Stored Procedure in Word

  1. #1

    How to call a Stored Procedure in Word

    Hi,
    I have a Store Procedure in SQL2005 Express and I'd like to know, how to call it in a Word macro. I'm a bit of Newbie with the connection string and all that stuff, if someone can explain me a bit, it would be nice.
    Thanks

  2. #2
    VBAX Master stanl's Avatar
    Joined
    Jan 2005
    Posts
    1,141
    Location
    Normally, I would just say set up an ADODB.Connection and Execute()... but could you be more specific about what the stored proc does? Stan

  3. #3
    Hi,
    Thanks for your answer but I solved my problem, here is the solution for anyone who needs help
    [vba]Function CheckID(ByRef oldPath As String, ByRef newPath As String) As Integer
    Dim Conn1 As ADODB.Connection
    Dim Cmd1 As ADODB.Command
    Dim Rs1 As ADODB.Recordset
    Dim Connect As String
    Dim Result As Integer
    Dim Exist As Integer

    Let Connect = "driver={sql server};server=servername;Database=DBName;UID=User;PWD=Pass;"
    'Etablit la connection
    Set Conn1 = New ADODB.Connection
    Conn1.ConnectionString = Connect
    Conn1.Open
    'Ouvre le recordset
    Set Cmd1 = New ADODB.Command
    Cmd1.ActiveConnection = Conn1
    Cmd1.CommandText = "YourStoredProcedureName"
    Cmd1.CommandType = adCmdStoredProc
    Cmd1.Parameters.Refresh
    Cmd1.Parameters(1).Value = newPath
    Cmd1.Parameters(2).Value = oldPath
    Set Rs1 = Cmd1.Execute()
    While Not Rs1.EOF
    Result = Rs1.Fields(0).Value
    Exist = Rs1.Fields(1).Value
    Rs1.MoveNext
    Wend
    Rs1.Close
    Conn1.Close
    Set Rs1 = Nothing
    Set Conn1 = Nothing
    End Function[/vba]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •