Re: Importing CSV File



Thanks, John. I'll try the Insert you suggest. But my gut feeling is
that it won't work, as the SQL Will be executing on the Server. ADP
Files don't have Jet Tables. Just like if I was using DTS or Bulk
Insert, the file would need to be visible to the Database server. That
would take some time to get setup by our security group.

I was using the Line input method, and parsing it. But by Parser is
very simple, and the data has commas within the fields on the csv
file. So it was mis-parsing. Here is my code:
---
Do 'Loop thru all records

Line Input #1, sLineInput
If i = 1 Then GoTo NextRecord 'Skip header

'Parse Data
'Manually parsed, as dates were not properly parsed when 'Input
#1, fld1, fld2, etc...'
'was used. It was splitting it into two flds, causing multiple
problems.

r = 1
StartPos = 1
Do While StartPos < Len(sLineInput)
iDelimPos = InStr(StartPos, sLineInput, ",")
If iDelimPos = 0 Then Exit Do
vDataPoint(r) = Mid$(sLineInput, StartPos, iDelimPos -
StartPos)
vDataPoint(r) = Replace(vDataPoint(r), conQuote, "") 'Remove
quotes, so data can be used
StartPos = iDelimPos + 1
r = r + 1
Loop
---

Could you suggest a better way to parse? I am limited it having a
comma as the delimiter, however the csv file has the offending fields
wrapped in quotes. I just havn't figured a way to accont for the
quotes yet.

On Feb 23, 3:05 pm, John Nurick <j.mapSoN.nur...@xxxxxxxxxxxxxx>
wrote:
Hi Bill,

I've never needed to use an ADP and don't have an instance of SQL server
to hand, so this is just suggestions.

1) Can you execute a SQL statement along these lines?

INSERT INTO CCYTrans
SELECT * TestImport
FROM [Text;HDR=No;Database=C:\MyFolder\;].MyFile#csv
;

2) As for writing VBA to read the file, I've never had much joy relying
on the Input # statement to parse text files. It seems much more
effective to use Line Input # to read the whole line into a string
variable and then parse it yourself.

On 23 Feb 2007 07:34:48 -0800, "Bill Schanks" <wscha...@xxxxxxxxx>
wrote:





I am trying to import data into A SQL Server Database via an Access
Project (.adp).

Here is a sample of the data downloaded to a CSV File:

02 Jan 2007 ,"01","I","108123959780" ...
02 Jan 2007 ,"01","I","108123959780" ...
02 Jan 2007 ,"01","I","108123959780" ...
02 Jan 2007 ,"01","I","108123959780" ...
...

When I use this:
docmd.TransferText acImportDelim,,"CCYTrans","C:\550417596.csv"

It imports it properly, however it names the table userid.CCYTrans
regardless if I have that table setup or not. I need it to import into
dbo.ccytrans. So that doesn't work. If I name the table dbo.ccytrans
It names the table userid.dbo_ccytrans. An Access bug in my opionion.
I don't want to have users create tables and then move the records to
the real table.

So I tried this code:

-----
Sub sImportTesting()

Dim BookDate, BankCode, AcctType, AcctNum
Dim i As Integer

Const conFileName As String = "C:\550417596.csv"

Open conFileName For Input As #1

Do While Not EOF(1)

Input #1, BookDate, BankCode, AcctType, AcctNum
Debug.Print BookDate
Debug.Print BankCode
Debug.Print AcctType
Debug.Print AcctNum
i = i + 1
If i = 50 Then Exit Do

Loop

Close

End Sub
-----

But is splits the first column into two. Here is the debug window
output:

sImportTesting
2
Jan 2007
01
I

Any ideas on how to get this to work properly?

--
John Nurick [Microsoft Access MVP]

Please respond in the newsgroup and not by email.- Hide quoted text -

- Show quoted text -

.



Relevant Pages

  • Re: Full-Text Catalog does not build...
    ... John, thank you. ... from time to time during population I have got event about SQL ... Server machine has 6GB RAM, SQL Server uses AWE and has 5GB memory. ... dbo properties PK_properties 7 1 cat_neu_prop1 ...
    (microsoft.public.sqlserver.fulltext)
  • Re: Return to previous stored procedure
    ... > John wrote: ... >> I am very weak on SQL 2000 so I am not sure if I am asking this right. ... > SourceSafe or an SQL IDE tool like Imceda Speed IDE for stored procedure ... It's never a good idea to edit direcly on the server, ...
    (microsoft.public.sqlserver.server)
  • Re: Windows Server 2003 Ent. x64 Edition - Full-text Tuning
    ... John - thanks for the info. ... Do you recommend running SQL using AWE for a dedicate DB server with 2G ... or is it 512M across all DB FT catalogs? ...
    (microsoft.public.sqlserver.fulltext)
  • Re: How can I Improve query speed?
    ... soundneedle@hotmail.com (John) wrote ... ... > and play around with. ... I'll need to go from Access to SQL ... > Server. ...
    (microsoft.public.excel.programming)
  • RE: Fulltext failure on a 2 node cluster
    ... Server full-text search resource online: "SQL Cluster Resource 'Full Text' ...
    (microsoft.public.sqlserver.clustering)

Loading