Obtaining SQL Records using Word Macro

J

Jon James

I need to write a macro that will query an SQL table and return a small number of records (no more than 10-15) into an array. Something like

Dim strConnection As Strin
strConnection = "C:\Bills\NTSERVER OrderData qryBills.odc
qstrString = "SELECT ClientCode, ClientName, MatterCode, Description, BillNo, Narrative, OSAmount FROM strConnection WHERE ClientCode = B0002 ORDER BY Narrative ASC
The client code 'B0002' will be a varable that the document will have already picked up
I can't seem to make this work
 
J

Jezebel

Since ClientCode is a string, you need to put quotes around it:

"...WHERE ClientCode = '" & MyClient & "' ORDER BY ..."

You've also got special things to if you're working with dates or with
strings that might themselves contain quote characters.


Jon James said:
I need to write a macro that will query an SQL table and return a small
number of records (no more than 10-15) into an array. Something like:
Dim strConnection As String
strConnection = "C:\Bills\NTSERVER OrderData qryBills.odc"
qstrString = "SELECT ClientCode, ClientName, MatterCode, Description,
BillNo, Narrative, OSAmount FROM strConnection WHERE ClientCode = B0002
ORDER BY Narrative ASC"
 

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