473,883 Members | 1,682 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do you map Access fields and Excel columns before importing

547 Contributor
I think it is called Import specification.
I usually import 3 Text fields ("IDNo" , "Name" and "Surname") from an Excel spreadsheet into an Access table called "Cyclist".
The fields may have different names in Excel ie

Excel ----------------- Access
IdentityNumber--------- IDNO
Firstname ------------ Name
Surname------------ Surname

The bottom line is that the fields in Excel may vary in name while in Access it stays the same.

When i press the Import button, i would like a "mapping" table or something similar to appear, and then i can manually link the correct Excel and Access fields.
Any ideas whether its possible and how it can be done?

I currently use this code to import from a specific directory. I still need to figure out the file open function for this (from Neopa), to avoid using a specific directory.
Expand|Select|Wrap|Line Numbers
  1. DoCmd.TransferSpreadsheet acImport, 10, "Cyclist", "c:\RTBU\AthleteData.xls", True, ""
It must not import duplicate "IDNo" data
Sep 8 '11
10 25121
patjones
931 Recognized Expert Contributor
This is going to seem convoluted, but bear with me. The basic idea is based upon knowing ahead of time what the column headings will be. In my instance, the users are running reports in a mainframe system and dumping the results into Excel. They then import those spreadsheets into the Access database using the interface that I built for them.

There are three different spreadsheets that they could import, each with different columns. The user specifies by picking from a combo box what it is they are going to import: pay data, leave data, or time data. They then browse for the spreadsheet using a file picker dialog that I raise.

Now, the mainframe always names the columns for a particular report the same thing, so provided that the user doesn't edit the spreadsheet prior to the Access import, I can tell Access what column names to expect for a particular spreadsheet by defining them in a comma delimited string. For example, the spreadsheet with pay data has columns Employee Number, EARN_DATE, Event Type, Hours1 and Amount. So I define a string like this:

Expand|Select|Wrap|Line Numbers
  1. strReqFieldList = "Employee Number,EARN_DATE,Event Type,Hours1,Amount"

At this point we want to make sure that the temporary table actually contains these columns, because it's possible that the user browsed for and imported something other than a pay data spreadsheet, even though they indicated that they were trying to import a pay spreadsheet.

So I made a function that takes the temporary table name and the required columns string as arguments. Essentially, it loops through the required column list, making sure that each column is in fact in the imported data (error handling omitted for clarity):

Expand|Select|Wrap|Line Numbers
  1. Public Function MissingField(strTableName As String, Optional strReqFields As String) As String
  2.  
  3.    'Connect to the table that we want to check for missing columns
  4.     Dim db As Database
  5.     Dim ltabdef As DAO.TableDef
  6.  
  7.     Set db = CurrentDb()
  8.     Set ltabdef = db.TableDefs(strTableName)
  9.  
  10.    'Variable to hold a column definition
  11.     Dim lflddef As Field
  12.  
  13.    'Array to hold the required column names
  14.     Dim arrReqFields() As String
  15.     arrReqFields = Split(strReqFields, ",")
  16.  
  17.    'Loop counter
  18.     Dim M As Byte
  19.  
  20.     For M = 0 To UBound(arrReqFields)
  21.        'Start out assuming that the field name does not exist in the imported data
  22.         MissingField = arrReqFields(M)
  23.  
  24.        'Enumerate through the columns in the table and check to see if the column name in question, arrReqFields(M), is in the collection
  25.         For Each lflddef In ltabdef.Fields
  26.             If lflddef.Name = arrReqFields(M) Then MissingField = "": Exit For
  27.         Next lflddef
  28.  
  29.        'If we come out of the column name check with a non-empty string, we have a missing column...so exit the function.
  30.         If MissingField <> "" Then Exit For
  31.     Next M
  32.  
  33. End Function

If the function returns a zero length string, there are no columns missing - and so we know that the imported data contains what we're looking for. I wrote this function a while ago. In hindsight there is probably a simpler way to do the check using some crafty SQL. I haven't gotten to that yet, but one of these days for sure.

What this whole process ensures is that, at minimum, the columns that you need for your business process are present.
Sep 9 '11 #11

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

Similar topics

5
5439
by: Tammy | last post by:
I am doing some genealogy research and I have discovered that there is a lot of data available on the web in text format. The problem is that the columns in the files are lined up by spaces. I'd like to be able to import these files into Access or Excel so that they can be sorted. What I plan on doing is adding in commas at the end of each field to create a csv file. What I need to know is how can I easily remove the spaces between...
12
2440
by: D. Shane Fowlkes | last post by:
This most likely belongs in another forum but I thought I'd start here. I have a COM Object written in VB6. The DLL will access MS Excel and use it's Object Library to write a customized report and saves it to a folder. The DLL even writes to a log for each step it takes so we can troubleshoot the problems (if any). This works fine on one machine but not another. The folder the DLL is trying to write to has full permissions assigned...
13
13264
by: nuti | last post by:
Hi all, I am fairly new to VB.I am trying to figure out as how to write a script so that i can read the data from an excel sheet to Access. can u guys please help me out? cheers, nuti
1
5748
by: garry.oxnard | last post by:
Can anyone help me to solve a problem which involves switching from Access to Excel (then back to Access) programatically please? I have an Excel template which, on open, also opens an Access database - containing a list of addresses. Sequence of events is = (1) Excel template opens in its default XXX.xls filename. (2) Code runs to save the spreadsheet as XXX.xls. (3) User clicks a button to open an Access database containing an
4
2051
by: ALaurie10 | last post by:
I am somewhat familar with access, but have no clue to modules and coding. I am trying to develop code or a module that will enable a user to import a specific excel spreadsheet and its' data into a table by pressing a command button. I am able to import excel, however it will not attach to existing spreadsheet. I find myself, having to build an append query for each import which is time consuming and inefficient. I have already checked, my...
1
3443
by: il0postino | last post by:
Apologies in advance for this newbie question! I have an Access form with an unbound embedded Excel chart on it(Called, OLEUnbound39) (Done on Access form by Insert > Object > Microsoft excel chart) I would like to place some records in to the underliing sheet and display the chart of this data using VBA. I use CopyFromRecordset. The code runs and the records are copied to the sheet, but apparently after this copy and before the next line...
1
3066
by: accessvbanewbie | last post by:
I would like to export a recordset from access to excel but after each record is exported I want to insert a new row. The first recordset does this ok. However, the second recordset onwards does not not export line excelsheet.Cells(9, 2) = rsschedulesrecords.Fields(2).Value. Below is my code. Please help? Private Sub CreateDailyRoster(rsschedulesrecords As DAO.Recordset) Dim excelapp As New Excel.Application Dim excelfile As...
6
9076
by: and1 | last post by:
hello .. hmm currently i'm working on vba in excel, apparently i use ADO to extract a table data from access to excel and it works fine. the problem is when i use the extracted data to create a chart using vba and it doesn't seem to display the data properly.. it is due to the text format when the data is extracted to excel.. how can i change it to number format when the table of data is extracted .. Here's the code: Dim cnt As New...
6
4142
by: passionateforjava | last post by:
Hi All, I am using struts application wherein I need to import file for some purpose.I have used input type="file" for the same which goes like: <input type="file" id="uploadFile" name="uploadFile" size="50"> I have the import button on which I have used onClick event to call javascript function submitValues() used to validate all the fields from the page which goes like: <input type="button" name="select" value="Import" class="CSSButton"...
1
4252
by: epifinygirl | last post by:
I am new to VBA writing so bear with me here. I have been searching the web but I keep finding answers in pieces which is more confusing! What I am trying to do is export a table from Access to Excel and run a macro (it's a formatting macro). My issue is that when Access exports the table, it resaves it and I lose the macro (The spreadsheet will be accessible to anyone so I can't just save it in the Personal workbook). When I try to copy the...
0
9781
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10734
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10836
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10407
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7114
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5793
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5982
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4606
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3230
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.