472,980 Members | 1,990 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,980 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 3380
NeoPa
32,548 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
443 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,548 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: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.