473,395 Members | 1,856 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,395 software developers and data experts.

ImportExportSpecifications

Does anyone know where I can find a writeup about the XML that Access 2007 uses in its ImportExportSpecification objects?

I'm using the ImportExportSpecifications to import text files into Access tables. I can create, modify, and execute the XML just fine, except for one thing. I can't specify to begin importing the text on some line other than the first.

For example, some of the text files I want to import contain a few header lines at the top of the text file with extemporaneous data. I want to specify in my ImportExport XML to begin importing on, say, the 10th line.

I tried to use the Access "Get External Data" UI to perform a test import to see if I could specify to begin importing text of some line other than the first line. I thought I could "Save import steps" and then look at the resulting XML in the CurrentProject.ImportExportSpecifications collection. But the UI doesn't provided the functionality to skip the first few lines of a text file, either.

(One could try to use Microsoft Excel, which does allow the user to skip the first few lines of a text file when importing. But Excel doesn't allow the user to save the import steps and view the XML!)

So, if someone knows where there's an explanation or writeup for the ImportExport XML, I would be very greatful. Or, if you know how to tell access how to start importing text on line other than the first, that would be even better!

Below is a sample of how I'm using the XML (not sure how it will come through in a post, though).

Thanks in advance for your help.
sphinney

Expand|Select|Wrap|Line Numbers
  1. private sub EXECUTE_IMPORT(byval MyFieldWidths as string, _
  2.                            byval MyFileName as string, _
  3.                            byval MyDelimChar as string, _
  4.                            byval MyTextQualChar as string)
  5. Dim BASE_XML As String
  6. Dim IMPORT_SPEC As ImportExportSpecification
  7. Dim CNTR As Long
  8. Dim COLS() As String
  9. Dim COLUMNstr As String
  10.  
  11.     'Create the base XML string
  12.     BASE_XML = "<?xml version=""1.0"" encoding=""utf-8"" ?>" & vbCrLf & _
  13.                "<ImportExportSpecification Path = ""<<DB_NAME>>"" xmlns=""urn:www.microsoft.com/office/access/imexspec"">" & vbCrLf & _
  14.                "      <ImportText TextFormat=""<<DB_TYPE>>"" FirstRowHasNames=""<<FIRST_ROW_NAMES>>"" FieldDelimiter=""<<DELIM>>"" TextDelimiter=""<<TEXT_QUAL>>"" CodePage=""437"" Destination=""OX_TXT_IMPORT_tbl"" >" & vbCrLf & _
  15.                "               <DateFormat DateOrder=""MDY"" DateDelimiter=""/"" TimeDelimiter="":"" FourYearDates=""true"" DatesLeadingZeros=""false"" />" & vbCrLf & _
  16.                "           <NumberFormat DecimalSymbol=""."" />" & vbCrLf & _
  17.                "             <Columns PrimaryKey=""""><<COLUMNS>>" & vbCrLf & _
  18.                "             </Columns>" & vbCrLf & _
  19.                "   </ImportText>" & vbCrLf & _
  20.                "</ImportExportSpecification>"
  21.  
  22.     'Split the MyFieldWidths string into an array
  23.     COLS = Split(MyFieldWidths , ",", , vbTextCompare)
  24.  
  25.     'Loop through the fields and build the column string
  26.     For CNTR = LBound(COLS) + 1 To UBound(COLS) + 1
  27.         COLUMNstr = COLUMNstr & "                 <Column Name=""Col" & CNTR & """ FieldName=""Field" & CNTR & """ Indexed=""NO"" SkipColumn=""false"" DataType=""Text"" Width=""" & COLS(CNTR - 1) & """ />" & vbCrLf
  28.     Next CNTR
  29.  
  30.     'Customize the base XML
  31.     BASE_XML = Replace(BASE_XML, "<<DB_NAME>>", MyFileName)
  32.     BASE_XML = Replace(BASE_XML, "<<DB_TYPE>>", "Fixedwidth")
  33.     BASE_XML = Replace(BASE_XML, "<<FIRST_ROW_NAMES>>", "true")
  34.     BASE_XML = Replace(BASE_XML, "<<DELIM>>", MyDelimChar)
  35.     BASE_XML = Replace(BASE_XML, "<<TEXT_QUAL>>", MyTextQualChar)
  36.     BASE_XML = Replace(BASE_XML, "<<COLUMNS>>", COLUMNstr)
  37.  
  38.     'Execute the XML
  39.     CurrentProject.ImportExportSpecifications.Add "TXT_IMPORT", BASE_XML
  40.     Set IMPORT_SPEC = CurrentProject.ImportExportSpecifications![TXT_IMPORT]
  41.     IMPORT_SPEC.Execute
  42.  
  43.  
Dec 19 '08 #1
3 7583
NeoPa
32,556 Expert Mod 16PB
I'm afraid I cannot be of too much help as I don't use either XML or Access2007.

However, I've done some importing / exporting in my time and I'm fairly sure there is no way to specify which line to start on. There IS an option to treat the first line as a header, but this is a simple boolean (flag - on or off). I suspect that is all you will get as far as that option is concerned.

If importing, it may be possible to import all the data and then remove x lines at the top of the table (can't be done as indexed of course at this point).

Good luck.
Dec 21 '08 #2
Thanks, NeoPa. I'd done a fair amount of searching on MSDN and the internet before posting here. I hadn't found much, but wondered if there was something I was missing. That's why I posted my question.

Your suggestion about importing all the data first is a good one. How would you do it?

I could import the entire file into a table/recordset with one field, then figure out how to parse it into multiple fields later. Problem is, some of my text files have 50+ fields and each line of text easily exceeds 255 characters (too big to put in a single "Text" field). I guess I could use a memo field, instead.

Does this sound reasonable or would you use some other object (as opposed to a table/recordset) to temporarily hold the text file data?

Thanks,
sphinney
Dec 22 '08 #3
NeoPa
32,556 Expert Mod 16PB
It all really depends on the structure of your data records.

I never use Memo fields myself, but I've heard they're very much less flexible than text fields.

I would consider the approach you suggested, but you may have to give some consideration to the actual format of the data itself.
Dec 22 '08 #4

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

Similar topics

7
JustJim
by: JustJim | last post by:
Hi all, I've got a client that upgraded to Vista and Office 07 thereby breaking one of my applications that they were using. Apologies for vagueness in the following question - I'm off-site and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
0
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,...
0
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...
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
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...

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.