Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Read / write a text file with HTML tags into MS Access

Posted on 2007-08-02
10
Medium Priority
?
281 Views
Last Modified: 2008-01-09
I have a MS Access 2000 Database.  I also have a text file that contains some text.  The text is wrapped in HTML tags like this:  <p>This is a string</p>.

1) It is possible to read/write the contents from/to a text file in MS Access?  (read into a textfield)
2) It is possible to keep the HTML tags, but not show them in the textfield?  Can textfields parse HTML?

Ellandrd
0
Comment
Question by:ellandrd
  • 8
  • 2
10 Comments
 
LVL 17

Assisted Solution

by:Barry Cunney
Barry Cunney earned 2000 total points
ID: 19615196
Yes it is possible to read a text file in MS Access

but there is no magical way of understanding and parsing HTML - You have to write some VBA code to build in this intelligence - there may be some third party DLL's out there to parse HTML
0
 
LVL 17

Assisted Solution

by:Barry Cunney
Barry Cunney earned 2000 total points
ID: 19615224
One way to read a text file is with the scripting oBJECT
Dim fs As FileSystemObject

Set fs = CreateObject("Scripting.FileSystemObject")
 
Set f = fs.OpenTextFile(DT & "x.txt")

a = f.ReadAll

MsgBox a
0
 
LVL 16

Author Comment

by:ellandrd
ID: 19615236
what does DT mean in this line:

Set f = fs.OpenTextFile(DT & "x.txt")
0
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
LVL 17

Assisted Solution

by:Barry Cunney
Barry Cunney earned 2000 total points
ID: 19615249
There is an MSXML2 object which can be used for parsing web pages
0
 
LVL 17

Assisted Solution

by:Barry Cunney
Barry Cunney earned 2000 total points
ID: 19615259
DT is just a variable
Ignore this - you can just pass in the actual file name
Set f = fs.OpenTextFile("yourfile.txt")
0
 
LVL 16

Author Comment

by:ellandrd
ID: 19615304
>>There is an MSXML2 object which can be used for parsing web pages

any more information - where can i find this?  where and how did you find this out?

can you tell me please...

ellandrd
0
 
LVL 17

Expert Comment

by:Barry Cunney
ID: 19615360
Option Explicit Function SaveWebFile(ByVal vWebFile As String, ByVal vLocalFile As String) As Boolean Dim oXMLHTTP As Object, i As Long, vFF As Long, oResp() As Byte 'You can also set a ref. to Microsoft XML, and Dim oXMLHTTP as MSXML2.XMLHTTP  Set oXMLHTTP = CreateObject("MSXML2.XMLHTTP") oXMLHTTP.Open "GET", vWebFile, False 'Open socket to get the website  oXMLHTTP.Send 'send request  'Wait for request to finish  Do While oXMLHTTP.readyState <> 4 DoEvents Loop oResp = oXMLHTTP.responseBody 'Returns the results as a byte array  'Create local file and save results to it  vFF = FreeFile If Dir(vLocalFile) <> "" Then Kill vLocalFile Open vLocalFile For Binary As #vFF Put #vFF, , oResp Close #vFF 'Clear memory  Set oXMLHTTP = Nothing End Function Sub TestingTheCode() 'This will save the Google logo to your hard drive, insert it into the  ' active spreadsheet, then delete the local file  SaveWebFile "http://www.google.com/intl/en/images/logo.gif", "C:\GoogleLogo.gif" ActiveSheet.Pictures.Insert "C:\GoogleLogo.gif" Kill "C:\GoogleLogo.gif" End Sub
0
 
LVL 17

Accepted Solution

by:
Barry Cunney earned 2000 total points
ID: 19615363
Option Explicit

Sub GetHtmlWithXML()
    Const sURI As String = "http://www.puremis.net/excel/"
    Dim oHttp As Object

    ' Create an XMLHTTP object
    On Error Resume Next
    Set oHttp = CreateObject("MSXML2.XMLHTTP")
    If Err.Number <> 0 Then
        Set oHttp = CreateObject("MSXML.XMLHTTPRequest")
    End If
    On Error GoTo 0
    If oHttp Is Nothing Then
        Exit Sub
    End If

    ' If domain needs ID and Password use thw code below
    ' oHttp.Open "GET", strURI, False, "DomainName\UserID", "PassWord"
    oHttp.Open "GET", sURI, False
    oHttp.Send
    Debug.Print oHttp.responseText
    Set oHttp = Nothing
End Sub
0
 
LVL 17

Assisted Solution

by:Barry Cunney
Barry Cunney earned 2000 total points
ID: 19615373
0
 
LVL 17

Assisted Solution

by:Barry Cunney
Barry Cunney earned 2000 total points
ID: 19615381
This example is for MS Excel VBA but you could adapt it to achieve what you want which is basically extract text from between certain tags
http://scriptorium.serve-it.nl/view.php?sid=40
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you’re using QODBC to update QuickBooks data from Microsoft® Access but Access is not showing the updated data, you could have set up QODBC incorrectly.
Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question