Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8589911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:10:17+00:00 2026-06-11T23:10:17+00:00

I have to connect a Word Document to a SQL Server with VBA in

  • 0

I have to connect a Word Document to a SQL Server with VBA in order to read and write records. Now, I’M really confused as of the many different ways to connect to a database. There’s ADO, ODBC and so on. I’ve seen very different ways of connecting a SQL Server database.
A co-worker wants me to use ODBC.

So: What is the best way to connect to a SQL Server database using ODBC in Office VBA?

An example for a SELECT and INSERT statement would also be appreciated.

Edit: Isn’t there something like “System.Data.SqlClient.SqlConnection” and “System.Data.SqlClient.SqlCommand” in VB .Net/C#?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T23:10:18+00:00Added an answer on June 11, 2026 at 11:10 pm

    This example uses ODBC:

    'Microsoft ActiveX Data Objects x.x library
    Dim cn As New ADODB.connection
    Dim rs As New ADODB.recordset
    
        cn.Open "DRIVER={SQL Server};SERVER=srv;" & _
           "trusted_connection=yes;DATABASE=test"
    
        rs.Open "SELECT * FROM table_1", cn
    

    This example uses OleDb

    'Microsoft ActiveX Data Objects x.x library
    Dim cn As New ADODB.connection
    Dim rs As New ADODB.recordset
    
        cn.Open "Provider=sqloledb;Data Source=srv;" & _
          "Initial Catalog=Test;Integrated Security=SSPI;"
    
        rs.Open "SELECT * FROM table_1", cn
    

    See also: http://www.connectionstrings.com/sql-server-2008

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to connect to a poorly implemented server that only understands Content-Type (capital-T)
i have this function pymssql.connect(host=my host,user=my user,password=my pass,database=mydb) I want to read the user
I have a function which opens a document in Word at a specified location:
I have a searching form that the user should enter a word. Till now
I have some Sql Server database, and I return the data with this method:
Sorry about the really ambiguous question, I really have no idea how to word
I have facebook connect button on a page of my site and I want
I have to do an assignment in JAVA in which I have to connect
I can't figure out why this is. I have a connect method that works
I have implemented Facebook Connect into a HTML page exactly as the tutorial explains

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.