Get a value for a SQL sproc

S

spnz

Hi there,

I have a sproc that basically gives me a unique number.

From word I would like to connect to the db and basically give me the number
from the sproc.

Does anyone have a piece of code that connects to a sql db and brings back
the result into a messagebox into word?


Any tips or advise would be really great!!
 
J

Jean-Yves

Hi,
Just posted that one to xl news

Have a try with this, using ADO :
Sub TEST()
'this requires to make a ref via tool
'to Microsoft ActiveX Data Object 2.x

Dim cn As ADODB.Connection
Dim rec As ADODB.Recordset

Set cn = New Connection
Set rec = New Recordset
'open the connection
cn.Open "Provider=SQLOLEDB.1;Data Source=Mydatabase/path", "userID",
"password"
'open the recordset
rec.Open "select myCcol from MyTable where myconditon = '" & "The
paramneter" &
"';", cn, adOpenForwardOnly, adLockOptimistic

Do While rec.EOF = False
msgbox rec.Fields("CreatedDate").Value
'optional for multiple records
'rec.MoveNext
Loop

rec.Close
cn.Close
Set rec = Nothing
Set cn = Nothing
End Sub
Regards
JY
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top