Results 1 to 11 of 11
  1. #1
    NejcZ is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Jun 2014
    Posts
    17

    Import HTML code fragments to Access

    I want to import HTML data which I get with email, to MS Access (2007). The problem is that files are badly formatted and standard import options are not avaliable for me.
    Basicly part of a file looks like that:


    Code:
    <tr>
    <td style="font:bold 11px/15px Arial,Geneva,Helvetica;width:220px">Name</td>
    <td style="font:normal 11px/15px Arial,Geneva,Helvetica">:</td>
    <td style="font:normal 11px/15px Arial,Geneva,Helvetica">John</td>
    </tr>

    Before and after that there are many lines of code which is useless to me. Is there a way to access "Name", connect it to a row in my Access table and insert it's value (John) into the table? Tips for what to search for will be appreciated, thanks.

  2. #2
    hapm is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2014
    Posts
    197
    Some solutions to select from:
    - Using XPath: I'm not sure how good Access 2k7's xml support is, but if your file is well formatted xml and you know how to handle XPath expressions, this will be only a small number of vba code lines. Perhpas there is some xml library you can reference to do this.
    - Using regular expressions: Would work fast and reliable. You will need knowledge in reg.exp. and you will need to reference the VB regular expressions library.
    - Using InStr to split the whole file up. The easiest but although most error prone and slowest method to use, but it willl not need a reference to an external library. I wouldn't use it if the file structure changes very often, or you have to import a heavy amount of such files.

  3. #3
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    What you have there is formatting for a webpage table. Not sure there is data inside that HTML that is worth storing in a relational database table.

    You can instantiate HTML elements as objects to get properties from the elements. I use Application.InternetExplorer.

    Here is some sample code
    https://www.accessforums.net/program...tml#post202672

  4. #4
    NejcZ is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Jun 2014
    Posts
    17
    Basicly I get HTML file in email, and it is always identical. Ofcourse it's not only 1 value that need storing to database
    What I'm looking for is a script, with which I can open HTML file from within my Access application, and when I do that, all data from HTML file will be transfered into the database.

  5. #5
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Well, I guess you can open the HTML file as text and save the text in a Memo field.

  6. #6
    hapm is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2014
    Posts
    197
    I gave you 3 options to choose from. Feel free to do so.

  7. #7
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    I would go with ItsMe's suggestion and open the HTML file as a text file and parse them.

    Look at the filesystemobject commands to manipulate files/folders.

    A sample file may be useful in helping you set up your parsing as well.

  8. #8
    hapm is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2014
    Posts
    197
    All 3 of my suggestions will require to read the files, either with FSO, VBAs default file reading operations or using some utility function of a third party XML library. ItsMe's approach utilizes the internet explorers HTML parser at this point. AFAIK IE supports some xpath abilities, that can be used to reliable navigate to the interesting elements.

  9. #9
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Quote Originally Posted by hapm View Post
    ... AFAIK IE supports some xpath abilities, that can be used to reliable navigate to the interesting elements.
    It does OK with XML but you still have to enumerate the child elements of the (forgot what they are called) header tags. Lots of VBA.

    If there is XML to parse, I would look at the options you listed.

  10. #10
    NejcZ is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Jun 2014
    Posts
    17
    Thanks, I got that sort of figgured out now.
    Now, I need a script that would somehow populate existing WORD document (template) with some data from Access table, putting the data at exactly the right position. Is that even possible?

  11. #11
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Anything is possible. Maybe what you want is Mail Merge. You can automate an existing word doc and go after the Mail Merge elements. Most mail merge examples are of the Word Doc itself opening and Automating the Access file. Most of these examples will require the DB file to be opened in exclusive mode.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Inserting HTML Code
    By warrenk in forum Queries
    Replies: 1
    Last Post: 06-13-2013, 04:47 PM
  2. Replies: 12
    Last Post: 04-30-2013, 02:41 AM
  3. Replies: 6
    Last Post: 04-26-2013, 03:51 PM
  4. Add javascript and html code in form
    By ashu.doc in forum Forms
    Replies: 11
    Last Post: 09-06-2012, 05:20 AM
  5. Import HTML files into access
    By mccrimmon in forum Programming
    Replies: 0
    Last Post: 02-15-2010, 03:40 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums