473,574 Members | 2,248 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 7031
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
5347
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). ...
5
1919
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...
6
6358
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...
0
1436
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...
1
5368
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...
0
3229
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...
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...
3
5316
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...
3
1558
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...
0
7831
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...
0
8262
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...
1
7842
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...
1
5641
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...
0
5331
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...
0
3768
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...
0
3785
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2258
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
0
1092
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...

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.