473,473 Members | 1,844 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Import CSV text file to MS Access DB

40 New Member
Hello,

Can anyone here has a code for importing CSV text file to Access table??

thanks in advance..

Sorry Debasis Das for disturbing...
Feb 22 '08 #1
5 5133
VBWheaties
145 New Member
Hello,

Can anyone here has a code for importing CSV text file to Access table??

thanks in advance..

Sorry Debasis Das for disturbing...
Direct from Microsoft:
http://www.microsoft.com/technet/scr...7/hey0206.mspx
Feb 22 '08 #2
MarkTingson
40 New Member
Direct from Microsoft:
http://www.microsoft.com/technet/scr...7/hey0206.mspx
Thanks sir. I'll give this a shot!
Feb 23 '08 #3
MarkTingson
40 New Member
i have a problem with this

Public Sub ImportToFile(srcRS As String, srcFile As String)

Const adOpenStatic = 3
Const adLockOptimistic = 3
Const ForReading = 1

Con_Open
Dim rsImport As ADODB.Recordset
Dim objFSO
Dim objFile
Dim strFile As String
Dim strArrFile() As String

Set rsImport = New ADODB.Recordset
'rsImport.CursorLocation = adUseClient
rsImport.Open srcRS, con, adOpenStatic, adLockOptimistic

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(srcFile)

Do Until objFile.AtEndofStream
strFile = objFile.ReadLine
strArrFile = Split(strFile, ",")

With rsImport
.AddNew
rsImport("strORnum") = strArrFile(0)
.Fields("strItemCode") = strArrFile(1)
.Fields("strItemName") = strArrFile(2)
.Fields("intqty") = strArrFile(3)
.Fields("intUnitPrice") = strArrFile(4)
.Fields("intAmount") = strArrFile(5)
.Fields("intDiscount") = strArrFile(6)
.Fields("intCharged") = strArrFile(7)
.Fields("intBranchFK") = strArrFile(8)
.Fields("datOrder") = CDate(strArrFile(9))
.Update
End With
Loop



rsImport.Close

End Sub

It says, "Subscript out of Range."

What was that mean? I actually trying to make this a procedure that i can call globally.

Call ImportToFile("SELECT * FROM tblDSR", App.Path & "\RECEivedfiles\MainDSR.txt")

I've already check my database fields and it is correct. Please help guys...

Thank you so much!
Feb 23 '08 #4
MarkTingson
40 New Member
Ahmm, guys i forgot to tell, the procedure is actually successful but my problem is, what does the "Subscript out of range" error means? and how can i get id of it.

Thanks again
Feb 23 '08 #5
VBWheaties
145 New Member
Ahmm, guys i forgot to tell, the procedure is actually successful but my problem is, what does the "Subscript out of range" error means? and how can i get id of it.

Thanks again
Subscript out of range error means an array index is invalid (there is no subscript index with that number).

From your code, it looks like one of the paranthesed values is the culprit. When you try to reference an array (like MyArray(4)) and the upper bound is 2, then you will get this error.

example:
Expand|Select|Wrap|Line Numbers
  1. Dim MyArray(2) As String 
  2. Msgbox MyArray(4) & " would throw Subscript Out of Range because 4 does not exist."
  3.  
Feb 25 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Chris | last post by:
Background: I am using a MS Access 2000 front end with SQL Server 8.0 back end. I have the requirement to import all text files (regardless of filename) from a given folder on the network into a...
1
by: DCM Fan | last post by:
Access 2K, SP3 on Windows 2K, SP4 All, I have an import spec set up with quoted Identifiers and comma-separated values. The text file is produced by a 3rd-party program of which I have no...
1
by: mark | last post by:
In Access 2000 and 2002, I have created an import specification to import the fixed-width recordset below into an existing table. I am having strange problems with the import of the date and time...
1
by: Dan | last post by:
Could someone please help me with auto importing a series of data files into an Access table. I tried to follow code given below in a previous messagebut i'm getting error messages. Here's my...
5
by: Johnny Meredith | last post by:
I have seven huge fixed width text file that I need to import to Access. They contain headers, subtotals, etc. that are not needed. There is also some corrupt data that we know about and can...
1
by: David Berry | last post by:
Hi All. I'm looking for any help or sample code that can show me how to make a file import wizard in ASP.NET (VB preferred) like the one that MS Access uses. I'm working on a web site where the...
0
by: NewbieSupreme | last post by:
I'm using PHPMyAdmin on an Apache2Triad install (latest version; 5.x.x, which installs PHP5 and PHPMyAdmin 2.8 as well). In Access, I exported a table to a text file, tab-delimited, text qualifyer...
1
by: Child of His | last post by:
I have been through every trick I know, or has been suggested. I have a one to two million line fixed field database in text format. I want to bring it into Access 97. When I use the external...
9
by: a | last post by:
Dear friends I want import data from CSV file to mdb file How can I do that in vb.net?
6
by: provor | last post by:
Hello, I have the following code that I am using when a user presses a button to import an excel file into a table. The code is hard coded to point to the correct table. This works great for this...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.