Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / September 2006

Tip: Looking for answers? Try searching our database.

Get a value for a SQL sproc

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
spnz - 28 Sep 2006 11:01 GMT
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!!
Jean-Yves - 28 Sep 2006 13:33 GMT
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

> Hi there,
>
[quoted text clipped - 8 lines]
>
> Any tips or advise would be really great!!
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.