468,741 Members | 2,038 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,741 developers. It's quick & easy.

Trying to import csv to excel - why isn't it looking for column names instead doing F numbers?

anoble1
233 100+
When I am trying to import a .csv into a table in access somehow it is wanting to match my columns not by name but by F1-F41 or the excel sheet. How can I get it to only match on column names that are defined in the excel sheet on the first row? This is a .csv file I am trying to import.

So right now I am just having excel create it's own table so I can see how it is importing.


Expand|Select|Wrap|Line Numbers
  1. Dim strfilename As String
  2. With Application.FileDialog(msoFileDialogFilePicker)
  3.         .Title = "Select the CSV file to import"
  4.         .AllowMultiSelect = False
  5.         .Filters.Clear
  6.         .Filters.Add "CSV Files", "*.csv", 1
  7.         .Filters.Add "All Files", "*.*", 2
  8.         If .Show = -1 Then
  9.             strfilename = .SelectedItems(1)
  10.             DoCmd.TransferText TransferType:=acImportDelim, _
  11.                 tableName:=acTable, filename:=strfilename
  12.             Else
  13.             Exit Sub
  14.         End If
  15.     End With
  16.  
  17.  
  18.  
  19.     Exit Sub
6 Days Ago #1

✓ answered by isladogs

If I understand you correctly the field names are being treated as the first row in your imported data.
The syntax is explained in the link: DoCmd.TransferText.
It includes a HasFieldNames option which is True or False:
DoCmd.TransferText (TransferType, SpecificationName, TableName, FileName, HasFieldNames, HTMLTableName, CodePage)

If omitted, HasFieldNames is treated as False

Surely your table name isn't really acTable? If it is, change it!

Then try changing that code to
Expand|Select|Wrap|Line Numbers
  1. DoCmd.TransferText TransferType:=acImportDelim, _
  2.                 tableName:=YourRealTableName, filename:=strfilename,
  3.                HasFieldNames:=True
Does that work?

You may find this link useful as well: TransferText examples

3 1233
NeoPa
32,129 Expert Mod 16PB
I'm able to confirm that this is a valid question as far as moderation goes but it's so poorly written I have no idea how to help.

Consider putting a bit more effort into writing a question that makes sense before submitting maybe.
6 Days Ago #2
isladogs
276 Expert 256MB
If I understand you correctly the field names are being treated as the first row in your imported data.
The syntax is explained in the link: DoCmd.TransferText.
It includes a HasFieldNames option which is True or False:
DoCmd.TransferText (TransferType, SpecificationName, TableName, FileName, HasFieldNames, HTMLTableName, CodePage)

If omitted, HasFieldNames is treated as False

Surely your table name isn't really acTable? If it is, change it!

Then try changing that code to
Expand|Select|Wrap|Line Numbers
  1. DoCmd.TransferText TransferType:=acImportDelim, _
  2.                 tableName:=YourRealTableName, filename:=strfilename,
  3.                HasFieldNames:=True
Does that work?

You may find this link useful as well: TransferText examples
6 Days Ago #3
NeoPa
32,129 Expert Mod 16PB
I suspect that IslaDogs' response has already given you what you need for this situaion (So I'll set that as Best Answer) but I would add some general advice that will hopefully help you in future - firstly not to have to post questions as you'll have fewer problems, but then to ask better questions.

The point is to use the compiler more heavily. In the VBA window select Debug | Compile {Project Name} when you're ready. This will fail if there are any syntax errors in your code and the associated message will lead you to a fix - or at least will be worth including in a question so that we can help you easily. It's never a good idea to post uncompiled code in your questions as it just wastes everyone's time - yours as much as ours. Compiling is easy and if your code doesn't even compile without error then it isn't going to start, let alone work as you intend. Not a good point to ask a question from ;-)
5 Days Ago #4

Post your reply

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

Similar topics

2 posts views Thread by Joe Gazda | last post: by
2 posts views Thread by Matthew Cascio | last post: by
1 post views Thread by Larry Bird | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
xarzu
2 posts views Thread by xarzu | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.