Solved

I need help saving to an Access 2013 table

Posted on 2014-12-09
5
406 Views
Last Modified: 2014-12-10
Hi Experts,
I have an Access 2013 application.  In my application, I open up an Excel spreadsheet, loop through values in a column and try to save those values to an Access table, but i get the following error:
Insert Error

Here is my table in design view:
Table in Design View
Here is my code, which I got from the following url:
 http://stackoverflow.com/questions/5310582/vba-to-import-excel-spreadsheet-into-access-line-by-line
The Author: Fink

My Code:
Option Compare Database

Private Sub Command3_Click()
    Dim xlApp As Object
    Dim xlWrk As Object
    Dim xlSheet As Object
    Dim i As Long
    Dim sql As String
   
    Set xlApp = VBA.CreateObject("Excel.Application")
   
    'toggle visibility for debugging
    xlApp.Visible = False
    
    Set xlWrk = xlApp.Workbooks.Open("C:\ExcelImportFile.xls")
    Set xlSheet = xlWrk.Sheets("Sheet1")
   
    For i = 1 To 10
        sql = "Insert Into tblTestImport (NOTE) VALUES (" & xlSheet.Cells(i, 2).Value & ")"
        DoCmd.RunSQL sql
    Next i
   
    xlWrk.Close
    xlApp.Quit
   
    Set xlSheet = Nothing
    Set xlWrk = Nothing
    Set xlApp = Nothing
End Sub

Open in new window

0
Comment
Question by:mainrotor
  • 2
  • 2
5 Comments
 
LVL 2

Assisted Solution

by:Krishna V
Krishna V earned 250 total points
ID: 40490618
Hi,
 I see couple of things in your code.

1) You are using Note a RESERVED work in Access as field name.
2) There is a difference in case of NOTE and Note, it should be a problem but can you please check about that.

Try to change field name to any name other than Note and see if that work.

Thanks,
0
 
LVL 22

Accepted Solution

by:
Kelvin Sparks earned 250 total points
ID: 40490619
Try

sql = "Insert Into tblTestImport (NOTE) VALUES ('" & xlSheet.Cells(i, 2).Value & "')"

Note that I have inserted a single quote before and after your double quotes around & xlSheet.Cells(i, 2).Value &

Kelvin
0
 

Author Comment

by:mainrotor
ID: 40490623
Kelvin and Krishna V,
I changed NOTE to Notex, and added the single quotes around & xlSheet.Cells(i, 2).Value &.

That worked!  But now every time it tries to save it prompt the following message:

Do you want to append message
How can I stop this from popping up?

thank you,
mrotor
0
 

Author Comment

by:mainrotor
ID: 40490624
Disregard my last question.  I figured it out.

mrotor
0
 
LVL 2

Expert Comment

by:Krishna V
ID: 40490727
Hi,
 Incase you HAVE to use RESERVED words as column names then the column name can be enclosed between [, ] in your query it should work.

You can try and check if the problem happens to be because of Reserved word.

Thanks,
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A company’s centralized system that manages user data, security, and distributed resources is often a focus of criminal attention. Active Directory (AD) is no exception. In truth, it’s even more likely to be targeted due to the number of companies …
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question