473,699 Members | 2,412 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Any way to validate spreadsheet headers before import?

Is there anyway to programatically confirm that specific field names
exist in the first row of a given Excel spreadsheet from code within
Access? I have code set up to import data from our spreadsheets from
HQ into our Access database for further use, using the first row as
column headings to determine the destination field in the Access table.
Since it's possible (and probable) that HQ could change the format of
the spreadsheets without my knowledge, I'd like to be able to confirm
that the needed fields are present (and named properly) before import.
I'm not very familiar with examining Excel data from within Access.
Any suggestions on how to do that?

Thanks!

Mar 28 '06 #1
2 7043
one way:
From within Access:


Open the spreadsheet
1) go to the desired worksheet (if they haven't changed the name on
you) ( In one application I had to go to sheet(1) and etc and getting
the name and seeing if part of it qualified since they change the tab
name EVERY MONTH. If you are going to import the sheet you will either
have to change the tab name to a standard name or change your import
statement for the change in range name.)
2) go to cell A1 and see if it is one of the names you require
a) if it is add 1 to a counter.
3) go to cell B1 and repeat the step 2 process.
4) go through as many columns as you reasonably think they can have.
5) close the spreadsheet
6) At the end, if the counter does not equal the number of required
fields you can then display an error message or form or whatever and
stop the rest of the process.

Danger of above is that two columns could have the same name and access
will not like it So you may want to set flags and change your logic
accordingly. However that then qualifies it for the "Inverse logic
rule" 90% of the code is for the 1% of the occurances.

In general there will probably be a problem with the import into an
existing table if they have added or changed any of the other field
names. So you will probably want to delete the import table and import
to a fresh table. (Then you may have a problem if the process is
aborted since it will not find the import table to delete the next time
through)

This is the voice of sad experience talking about the two possibilities
indicated.

Hope this gave you some ideas.

Ron

Mar 28 '06 #2
I'd do something like this to open an empty recordset whose Fields get
their names from the column headings:

Dim S As String
Dim R As DAO.Recordset
Dim F As DAO.Field
Dim FileName As String
Dim SheetName As String

...
S = "SELECT * FROM [Excel 8.0;HDR=Yes;Dat abase=" _
& FileName & "].[" & SheetName & "] WHERE False;"

Set R = CurrentDB.OpenR ecordset(S, dbopensnapshot)
For Each F in R.Fields
'do stuff with F.Name
...
Next
R.Close
On 28 Mar 2006 12:49:35 -0800, go****@darincli ne.com wrote:
Is there anyway to programatically confirm that specific field names
exist in the first row of a given Excel spreadsheet from code within
Access? I have code set up to import data from our spreadsheets from
HQ into our Access database for further use, using the first row as
column headings to determine the destination field in the Access table.
Since it's possible (and probable) that HQ could change the format of
the spreadsheets without my knowledge, I'd like to be able to confirm
that the needed fields are present (and named properly) before import.
I'm not very familiar with examining Excel data from within Access.
Any suggestions on how to do that?

Thanks!


--
John Nurick [Microsoft Access MVP]

Please respond in the newgroup and not by email.

Mar 29 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
5357
by: Stan Brown | last post by:
URL: http://www.acad.sunytccc.edu/instruct/sbrown/stat/mygrades.htm As I read the spec, I need _either_ data= and type= _or_ classid= and codetype=. I've tried it both ways and neither works. I googled, but was overwhelmed with results and none of them seemed hopeful (probably because I don't see how to frame a query specifically enough). Some enlightenment, please?
5
1926
by: Colleyville Alan | last post by:
I need to import a spreadsheet into an Access table. The spreadsheet has performance for mutual funds for various periods. The problem is that if there is no info for a particular period, the spreadsheet contains a dash in the cell (for example if the fun is only 4 years old and I look in the columns for 5-year and 10-year performance). I cannot change the dashes to blank with a global change, the negative numbers would lose the...
6
6366
by: syvman | last post by:
Hi everyone... I am pulling my hair out trying to do this, and was wondering if someone could give me some assistance... I have an Excel spreadsheet containing several worksheets. I'd like to be able to take all of the data from the second column (B) of each worksheet and append that raw data to an access table. The columns in the spreadsheet do not have headers for use as field names (it's my assumption that my table should have a...
0
1439
by: Jer | last post by:
I am using TransferSpreadsheet from an ADP file to import an Excel spreadsheet into an MSDE database. On one computer, when I run the code to import the spreadsheet, it prompts for an SQLServer login. The same user can try it on a different computer and it will work fine. Data in the tables of the database can be viewed and edited on the bad computer. But the spreadsheet cannot be imported. I even tried the Get External Data->Import
1
5375
by: socasteel21 via AccessMonster.com | last post by:
I have a spreadsheet that has 3 tabs each of the worksheets is setup exactly like a cooresponding table in Access. I created a button that should import each tab to a new table and then append those records in the new table to the cooresponding table. Here is my code for the button: ----(start of code)----------------------------------------------------------- ------------------------------------------------------------------- ...
0
3232
by: ssrirao | last post by:
There is an Excel Spreadsheet containing data, residing in an internet site. It’s very easy to Import data from a local Excel Spreadsheet into SQL Server Database Table using DTS. But in my case the Excel spreadsheet resides an internet site which has a static name (Example xyz.xls) but varying data inside it. The spreadsheet contains three columns a, b, c and data below it. Only data get updated weekly So basically I have to automate...
2
1787
TMS
by: TMS | last post by:
The spreadsheet is due today and i needed help with the last two parts of the spreadsheet, so I went to my teacher. My spreedsheet was working BETTER before he made me change it. Now it prints a widget address in one of the cells for no apparant reason (I can't locate why the event is doing that), and it doesn't evaluate. He wants me to use 2 dictionaries: One that holds the cell number and expression, and Two that holds the result of...
3
5324
by: D.Stone | last post by:
I'm trying to import an Excel spreadsheet into an existing Access table using Office 2003. Ultimately, the plan is to do it programmatically using TransferSpreadsheet, but to check that the file has no problems, I've done it manually with the Import Spreadsheet wizard. The worksheet has 43 rows, and I import a named range defined as "=Sheet1!$C:$E". The import works, but I get a table with 64K rows, all but 43 being blank!
3
1564
by: GiftX | last post by:
Good morning members. I am using VB6 to generate a spreadsheet. My module is working okay but one of my objectives is to print an underline after writing each record in the spreadsheet, just to show where one record ends and the next begins. However, even if I process only one record and try to print it, it prints several blank pages including underlines, even if there are no records. How can I instruct it to strictly print an underline...
0
8697
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8622
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,...
1
8930
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
8892
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
7767
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6538
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5878
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
4634
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3062
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

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.