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 7415143
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:14:28+00:00 2026-05-29T07:14:28+00:00

I am trying to use the INSERT INTO command to write data into an

  • 0

I am trying to use the INSERT INTO command to write data into an Access 2007 file from a excel 2010 file. The data is contained in the “NewProj” worksheet in the Tool_Selector.xlsm excel file and it needs to be written to the “Tool_Database.mdb” file but unfortunately I have received several different errors.. This is what I currently have

Sub AddData()
  Dim Cn As ADODB.Connection
  Set Cn = New ADODB.Connection

  Cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Tools_Dev\_Tool_Selector\Tool_Selector.xlsm;Extended Properties=Excel 8.0;" _
        & "Persist Security Info=False"

  Cn.Execute "INSERT INTO Project_Names IN 'D:\Tool_Database\Tool_Database.mdb' SELECT * FROM Worksheets("NewProj").Range("A2").Value"

  Cn.Close
  Set Cn = Nothing
End Sub

I got the code from this thread: Insert Data from Excel into Access using VBA

I just need to transfer the value of individual cells.

Thanks.

  • 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-05-29T07:14:29+00:00Added an answer on May 29, 2026 at 7:14 am

    The problem is that you’re using VBA code IN the SQL statement. The following line will compile but fail upon execution:

    Cn.Execute "INSERT INTO Project_Names IN 'D:\Tool_Database\Tool_Database.mdb' SELECT * FROM Worksheets("NewProj").Range("A2").Value"
    

    It fails because you’re still in the SELECT statement when you make use the VBA functions of Worksheets(), .Range, and .Value. IIRC, you should be able to use SQL syntax to select a particular range from a sheet. The proper syntax for that should be:

    "SELECT * FROM [Sheet$]"
    

    If you want a particular range then you’d try:

    "SELECT * FROM [Sheet$A1:C20]"
    

    There’s a Microsoft article on this at: http://support.microsoft.com/kb/257819 if you’re looking for more information on using ADO with Excel. The Scripting Guys also wrote a decent article that helped me understand it a few years back: http://technet.microsoft.com/en-us/library/ee692882.aspx.

    Hopefully that helps you solve your problem. However, I will leave you with one word of warning. I remember running into some really weird issues when querying an already open Excel spreadsheet when I was first using this code. If I was querying an Excel spreadsheet that was already open then I would run into an issue where memory would be leaked and Excel would eventually run out of memory to use. The only way to solve the problem was to close Excel entirely. It also didn’t matter whether the ADO references were properly closed/cleared or not.

    In fact, I just Googled it to double check and here’s an article on the bug: http://support.microsoft.com/default.aspx?scid=kb;en-us;319998&Product=xlw.

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

Sidebar

Related Questions

I am trying to read from a csv file and insert the data into
I'm trying to insert some data into SQL from Excel VBA. The SQL commands
So I am trying to use jQuery to insert data from an ajax call.
I'm trying to transfer data from a DataSet into an Excel workbook. Unfortunately, I
I'm trying use mod_rewrite to rewrite URLs from the following: http://www.site.com/one-two-file.php to http://www.site.com/one/two/file.php The
I'm trying to insert 10000 values into Oracle from C# and am using the
I'm trying to insert a System.DateTime into an Access database using a parameterized OleDbCommand
I need to use bash to insert a line into a python file. This
I am trying to insert data into MS SQL server 2008 using Ole DB.
I am trying to use a Rake task to migrate some legacy data from

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.