Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 188
Default Can I get all fields for all tables in a FoxPro DB into excel (one table per sheet) automatically?


Hi All,

Is there any way to get all tables (and all fields in each table) into
excel automatically without having to manually enter all table names
and field names into SELECT queries?

Ideally, one sheet per table with the sheets named with the table
names, but anything close would be good.

Thanks,

Alan.


--
The views expressed are my own, and not those of my employer or anyone
else associated with me.

My current valid email address is:



This is valid as is. It is not munged, or altered at all.

It will be valid for AT LEAST one month from the date of this post.

If you are trying to contact me after that time,
it MAY still be valid, but may also have been
deactivated due to spam. If so, and you want
to contact me by email, try searching for a
more recent post by me to find my current
email address



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,163
Default Can I get all fields for all tables in a FoxPro DB into excel (one

It is possible but would require some pretty intense coding which I don't
have time to work out right now. But the key would be using ADO to connect
to the database and then you can use the OpenSchema method to read the names
of the tables. You could iterate through these in a loop, append a worksheet
to your workbook, and then use standard ADO recordset methods to retrieve the
data from each table (SELECT * FROM TABLENAME should be sufficient). You
could get column headers, if desired, from the Field.Name property (iterating
through the fields).

Sorry I can't do all the details, but for info on reading the database
schema see this:
http://msdn.microsoft.com/library/de...openschema.asp

If you need info on ADO methods in general:
http://msdn.microsoft.com/library/de...troduction.asp
--
- K Dales


"Alan" wrote:


Hi All,

Is there any way to get all tables (and all fields in each table) into
excel automatically without having to manually enter all table names
and field names into SELECT queries?

Ideally, one sheet per table with the sheets named with the table
names, but anything close would be good.

Thanks,

Alan.


--
The views expressed are my own, and not those of my employer or anyone
else associated with me.

My current valid email address is:



This is valid as is. It is not munged, or altered at all.

It will be valid for AT LEAST one month from the date of this post.

If you are trying to contact me after that time,
it MAY still be valid, but may also have been
deactivated due to spam. If so, and you want
to contact me by email, try searching for a
more recent post by me to find my current
email address




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Can I get all fields for all tables in a FoxPro DB into excel (one table per sheet) automatically?

Hi Alan,

I am not sure what version was used to create the files, but I can
access the tables manually as follows:

There is an ODBC connection of type 'Visual Foxpro Database (DBC file)
so you are spot on there.

As you mention it does appear that this is just a link to the actual
tables which are in separate DBF files (I think).


The actual tables come in 3 parts: the DBF file is the table itself, the FPT
file (optional) contains the Memo field data, and the CDX (optional)
contains the indexes.

If I were doing this in Visual FoxPro (VFP9 is the latest version)
it would be really simple. :-)


I looks like I am!

Does that mean there is an easy to achieve what I need to do or do you
mean I would need to have VFP9 installed (which I don't)?


From a program written in VFP and run in the VFP IDE or as an executable the
code would look like this:

*-- Get an array of the DBFs in the directory
*-- Column 1 has file names
ADir(ArrayOfFiles, "*.dbf")

*-- Create the Excel Workbook
oExcel = CreateObject("Excel.Application")
oExcel.Visible = .T. && For testing
oExcel.Workbooks.Add()

*-- Iterate through column 1 of the array
*-- More than one way to do this but here's one
For nCount = 1 To Alen(ArrayOfFiles)
*-- If this element is in column 1
If ASubscript(ArrayOfFiles, nCount, 2) = 1
With oExcel
.Worksheets.Add()
cFileName = Alltrim(ArrayOfFiles(nCount))
Use (cFileName) Shared && Use opens a table
_Vfp.DataToClip(,,3) && Creates tab-delimited text
.ActiveSheet.Name = cFileName
.ActiveSheet.Cells(1, 1).Activate
.ActiveCell.PasteSpecial()
EndWith
EndIf
EndFor

oExcel.SaveAs("MyWorkbook")
oExcel.Quit()
oExcel = .NULL.
Clear All && Release all variables and close all tables

--
Cindy Winegarden MCSD, Microsoft Most Valuable Professional
www.cindywinegarden.com
Blog: http://spaces.msn.com/members/cindywinegarden


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Pivot tables missing fields from defined table Emma Excel Discussion (Misc queries) 2 October 31st 08 01:32 PM
Pivot Table Cycling Through Page Fields Automatically nrehman Excel Discussion (Misc queries) 14 October 13th 05 07:32 PM
automatically change the order of fields in a sheet minrufeng[_5_] Excel Programming 1 August 14th 05 09:39 PM
Mapping Tables.Fields from a data source to my MS Access Table Structure Mark Roach Excel Programming 0 April 9th 05 11:03 PM
Excel 2003 and FoxPro tables WKIII Excel Programming 1 June 15th 04 04:55 PM


All times are GMT +1. The time now is 06:57 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"