473,419 Members | 4,373 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,419 software developers and data experts.

Import Excel cells to a table but field names are different in both

547 512MB
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)
Nickname;Surname; DOB; Identity_No
In the Access 2007 table(tblCyclists) the same fields in this sequence are called:
First_Name; Surname;Birthdate;IdNo.

I want to import the data from the "sheet 1" in the Excel spreadsheet (Cyclist.xls, into an Access table called tblCyclists. (the Excel column names will always stay the same and can be used as such in VBA)
I use this code but the field names must be the same then.
Expand|Select|Wrap|Line Numbers
  1. Dim strPath As String
  2.  
  3.     With Me
  4.          strPath = Left(.lblFile.Caption, InStrRev(.lblFile.Caption, "\"))
  5.         strPath = FSBrowse(strStart:=strPath, _
  6.                            lngType:=msoFileDialogFilePicker, _
  7.                            strPattern:="MS Excel,*.xls")
  8. If strPath > "" Then
  9.              .lblFile.Caption = strPath
  10.              MsgBox "The data hase been successfully imported ", vbInformation, "Data imported"
  11.            Call DoCmd.SetWarnings(False)
  12.  
  13.               Call DoCmd.TransferSpreadsheet(acImport, acSpreadsheetTypeExcel9, "tblCyclist", strPath, True, "")
  14.  
  15.  
  16.  
  17.             Call DoCmd.SetWarnings(True)
  18.  
  19. End If
  20.      End With
Any suggestions please!
May 27 '13 #1

✓ answered by zmbd

There are a lot of ways to handle getting the data from excel into access. The biggest issue discussed when this comes up is not so much the fetching of the data in as much as it is the validation of the imported data against datatype and so forth.

So if you'll stipulate that there are some intrinsic hazards with data validation:

Transferworksheet method. Use this method to bring the data into a temporary table and then use and append
(http://bytes.com/topic/access/answer...te-access-info) see my post ... #4? I've also made a dozen posts going over this method in various other threads.


Another method (and I've also used this method; however, I now use the transfer worksheet more often):

1) Using the external data, create a linked table to the excel
2) Create an append query

So for example (I'm using really generic names here):

Excel workbook "Book1.xls" in "My documents"
Expand|Select|Wrap|Line Numbers
  1. Sheet 1, starting in Row 1 Column A
  2. zt1    zt2    zt3
  3. 1    a    app
  4. 2    b    bck
  5. 3    c    cmd
  6. (...)
Create a link to this table and the sheet (I just used the External data ribbon)

Say in our "Database1" we have "Table1" with:
[ID] (auto number - pk)
[boo] (just a text field)
[money] (just another text field)

Now create your append query

Expand|Select|Wrap|Line Numbers
  1. INSERT INTO Table1 ( ID, boo, [money] )
  2.    SELECT linked_Sheet1.zt1 
  3.           ,linked_Sheet1.zt2 
  4.           ,linked_Sheet1.zt3
  5.    FROM linked_Sheet1;
  6.  
Run your query.

So long as "zt1" column data is numeric and doesn't repeat you can append/insert to your heart’s content.
You should be able to create the same link and append query within a VBA.
Using either method, you can always place constraints within the append SQL.

3 8040
zmbd
5,501 Expert Mod 4TB
There are a lot of ways to handle getting the data from excel into access. The biggest issue discussed when this comes up is not so much the fetching of the data in as much as it is the validation of the imported data against datatype and so forth.

So if you'll stipulate that there are some intrinsic hazards with data validation:

Transferworksheet method. Use this method to bring the data into a temporary table and then use and append
(http://bytes.com/topic/access/answer...te-access-info) see my post ... #4? I've also made a dozen posts going over this method in various other threads.


Another method (and I've also used this method; however, I now use the transfer worksheet more often):

1) Using the external data, create a linked table to the excel
2) Create an append query

So for example (I'm using really generic names here):

Excel workbook "Book1.xls" in "My documents"
Expand|Select|Wrap|Line Numbers
  1. Sheet 1, starting in Row 1 Column A
  2. zt1    zt2    zt3
  3. 1    a    app
  4. 2    b    bck
  5. 3    c    cmd
  6. (...)
Create a link to this table and the sheet (I just used the External data ribbon)

Say in our "Database1" we have "Table1" with:
[ID] (auto number - pk)
[boo] (just a text field)
[money] (just another text field)

Now create your append query

Expand|Select|Wrap|Line Numbers
  1. INSERT INTO Table1 ( ID, boo, [money] )
  2.    SELECT linked_Sheet1.zt1 
  3.           ,linked_Sheet1.zt2 
  4.           ,linked_Sheet1.zt3
  5.    FROM linked_Sheet1;
  6.  
Run your query.

So long as "zt1" column data is numeric and doesn't repeat you can append/insert to your heart’s content.
You should be able to create the same link and append query within a VBA.
Using either method, you can always place constraints within the append SQL.
May 27 '13 #2
Seth Schrock
2,965 Expert 2GB
Try setting the Has Field Names argument to False and set your range to not include the top row of data (which is where I assume your field names are located).

Edit: Cross posted with Z. Try his first as he has more experience with this sort of thing.
May 27 '13 #3
neelsfer
547 512MB
I think the way to go as mentioned above, is to import the data to a "temp table",change some of the field types (txt to numbers as required - RaceNo1: IIf([RaceNo] Like "#*",Val([RaceNo]),[RaceNo])) in a query and then append it into the main table.
May 28 '13 #4

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

Similar topics

3
by: Tom | last post by:
Data is collected over time in an Excel worksheet with 20 columns. The Excel worksheet starts out as a copy of a template as is filled in as data is collected. Eventually the worksheet file is...
2
by: Ralph | last post by:
I'm trying to import a range of cells from an Excel spreadsheet into a table in access. The first row contains column labels, but I cannot use those as my field names, both because of their format...
1
by: Bob | last post by:
When displaying data from the database, very often the field names are not suitable so custom headings have to be created, For example, the column storing zip code may be named zip, but when...
3
by: MLH | last post by:
Generally, I do not monkey with renaming controls on forms whose name, by default, matches the name of their related table fields. But I noticed the following today If IsNull(Me!VColor) Then...
2
by: amy | last post by:
Hi, all: i am a new end user of access, now I have many excel files need to import to One table in access (combine all excel files into one table in excel). In excel files, some columns will have...
3
by: zeno | last post by:
Hi All ! is it possible to use variable table and/or field names in stored procedures i.e. construct the name of a table/field based on an input parameter as in : create procedure toto(in...
11
by: Tim Hunter | last post by:
Hi I am using WinXP and Access 2003 Is it possible to store the field names of a table in an array and then loop through the array and update the table using the field names stored in the array? I...
1
by: sesling | last post by:
I have several large text files that are comma delimited and I want to move the data into my access db. The problem I have is that the text files do not have column headers. When I import the file...
1
by: thadson | last post by:
Hi, I'm trying to import specific cells from MS Excel 2000 spreadsheets to MS Access 2000 tables then move the spreadsheets to a different directory. I'm very new to this and I'm having trouble...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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
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: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.