Consulting

Results 1 to 2 of 2

Thread: Present SQL result in Word???

  1. #1
    VBAX Regular
    Joined
    Mar 2012
    Location
    Örebro, Sverige
    Posts
    8
    Location

    Present SQL result in Word???

    Yesterday I learned how to access our database with VBA, extract the information I want and present it in Excel.

    But now to the next challange: I need to do the same query in Word and present the result in a textbox. I´ve searched the Internet but it´s to complicated. I need someone to explain it to me. There is a Swedish saying: "Talk to a farmer as a Farmer".

    This is the code I have for Excel. As I´m not able to present the result in Word I have no idea if this works in Word.

    [VBA]Sub GetDataTest()
    Dim objMyConn As ADODB.Connection
    Dim objMyRecordset As ADODB.Recordset
    Set objMyConn = New ADODB.Connection

    objMyConn.ConnectionString = "Provider=SQLOLEDB;Data Source=myServer;Initial Catalog=myDB;User ID=myID;Password=myPW;"
    objMyConn.Open

    Set objMyRecordset = New ADODB.Recordset

    objMyRecordset.ActiveConnection = objMyConn
    objMyRecordset.Source = "SELECT [First Name] FROM EmployessTable WHERE [Employee]='10000'"
    objMyRecordset.Open

    ' Here´s where I´m lost....
    ActiveSheet.Range("A1").CopyFromRecordset objMyRecordset

    objMyRecordset.Close
    objMyConn.Close

    Set objMyConn = Nothing
    Set objMyRecordset = Nothing

    End Sub[/VBA]

    Could someone plz explain to me how to get this working in Word 2007?

    /Cederbusch

  2. #2
    VBAX Regular
    Joined
    Mar 2012
    Location
    Örebro, Sverige
    Posts
    8
    Location
    Solved this!

Posting Permissions

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