473,287 Members | 1,435 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

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

anoble1
245 128KB
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
Jul 21 '21 #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 3403
NeoPa
32,554 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.
Jul 21 '21 #2
isladogs
454 Expert Mod 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
Jul 21 '21 #3
NeoPa
32,554 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 ;-)
Jul 22 '21 #4

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

Similar topics

2
by: Joe Gazda | last post by:
I'm a relative newbie to PHP, but have been able to put together some PHP code to generate a CSV/XLS file from a Query result. Now, I would like to include custom column names instead of the MySQL...
0
by: Andrew | last post by:
With command-line interface ( 3.23.37, UNIX Socket ) all is well with column aliasing. However, column aliases disappear in Excel, over ODBC, when there are multiple (joined) tables in the query. ...
2
by: Matthew Cascio | last post by:
My understanding is that using reserved words as column names is allowable as long as they are quoted. I am trying to create a table dynamically with columns defined by the first row of a text...
2
by: Joe | last post by:
Hi All, I am new to using the Access DB and I need some help if someone is able to give it to me. What I want to do is get the names of the columns of certain tables. Not the data in the table...
1
by: Larry Bird | last post by:
I've created a AlertDataClass below within the class I have tables and column that I've create. In the AlertDataAccess class I'm trying to insert data into my tables. AlertDataAccess is a Module...
0
by: zacks | last post by:
I am trying to use the Microsoft Text Driver to access data in a text file via ODBC calls. Everything has worked fine so far. I am now trying to implement support for a file that has a special...
2
by: OpusMagnum | last post by:
I'm trying to import an Excel spreadsheet and append a current table within the Database. I have have all the Access column names within the spreadsheet. Access wants to import a blank column and...
1
by: mushtaqawais | last post by:
Hi All, I am new to MS SQL , when I import an excel file that contains "Dates" in its column names to MS SQL 2008, the date is not displayed in column name in MS SQL. Rather it shows F3, F4, F5. I...
0
by: prashantdixit | last post by:
Hi, I have beent trying importing Excel data with one column containing PDF/JPEG file name to access 2007. I have a Excel file with few columns One of the columns named as "Reference". The...
3
by: neelsfer | last post by:
Is there a way to import and "hard code" data from Excel where the cell(Excel column) and Access field names are different for the same data. In Excel i have the following columns(cells) ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

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.