Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
| Search | Today's Posts | Mark Forums Read
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old July 11th, 2008, 04:34 PM
Registered User
 
Join Date: Jul 2006
Location: hyderabad, andhra pradesh, India.
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to sparsh2010
Default Read file and store it to database

Hi,

     I am trying to read file (C:\Test.txt) and read it line by line and store the values into a MS access database table name TEMP
ERROR : Run Time Error 3134
TEMP
Field = EMPLOYEE (Primary Key)

i have tried following code

Dim sFileText, strPictureFilename As String
Dim iFileNo As Integer

Open "C:\Test.txt" For Input As #iFileNo

Do While Not EOF(iFileNo)
        Input #iFileNo, sFileText
        strPictureFilename = sFileText

         SQL = "Insert Into TEST EMPLOYEE Values '" & strPictureFilename & "'"

        DoCmd.RunSQL SQL
Loop

  Close #iFileNo


Pramod Chandra
  #2 (permalink)  
Old July 14th, 2008, 06:53 AM
Friend of Wrox
Points: 9,611, Level: 42
Points: 9,611, Level: 42 Points: 9,611, Level: 42 Points: 9,611, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2004
Location: Washington, DC, USA.
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Can you post some sample data from the text file, and the table structure from the table? This is a pretty easy process. I use Scripting.FileSystemObjects, however.

It also looks like you are having issues with the EMPLOYEE field being the PK field and duplicate values trying to be inserted. Is that that problem?

Please post more information and I will post some tested code.

mmcdonal

Look it up at: http://wrox.books24x7.com
  #3 (permalink)  
Old July 14th, 2008, 03:31 PM
Friend of Wrox
 
Join Date: Jun 2008
Location: Snohomish, WA, USA
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Your SQL is wrong.

The format of INSERT is
    INSERT INTO <tablename> ( <list of fields> ) VALUES( <list of values > )

The parentheses are *NOT* optional!

So:

SQL = "Insert Into TEST ( EMPLOYEE ) Values ('" & strPictureFilename & "')"
  #4 (permalink)  
Old July 17th, 2008, 08:27 AM
Friend of Wrox
Points: 9,611, Level: 42
Points: 9,611, Level: 42 Points: 9,611, Level: 42 Points: 9,611, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2004
Location: Washington, DC, USA.
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Did this work for you?

mmcdonal

Look it up at: http://wrox.books24x7.com


Similar Threads
Thread Thread Starter Forum Replies Last Post
Read excel file into database wk ASP.NET 2.0 Basics 7 June 12th, 2007 06:53 AM
How to store MS Word File in database kesar SQL Language 2 March 1st, 2007 06:34 AM
DTS Package, XML task. Read XML file and store it Victoria SQL Server DTS 0 July 24th, 2006 02:43 PM
how to store file in sql server 2000 database vivekkumar_23 SQL Server 2000 1 February 27th, 2006 10:41 PM
how to store text file in database vivekkumar_23 Servlets 1 February 13th, 2006 05:29 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.