Question : Importing/Linking Data from URL

For a Word VBA application under development, I need to import data that resides on a web server. I have the URL and appropriate credentials. For reasons too tiresome to go into, the data need to be exported from the web-based database into a file that I download/access. On the web side, my developer can export to CSV, HTML, XML or what have you. On the client side, I want a code-only solution (want to distribute my solution only, and not an ODBC DSN).

So the challenge is: what's the most efficient and low-maintenance code-only solution to getting the data from http://www.myserver.com/myfile.htm (or .csv or whatever) into a recordset?

PS: Planted this in the Access topic because it's more of a DB VBA problem than a Word problem.

PS2: I'll double points for a 'URL in, RecordSet out' function example.

Answer : Importing/Linking Data from URL

That's a good question.

I'm quite confident in saying that you cannot simply import from an URL with Access. I would look for an appropriate intermediate layer. Perhaps a form with the Microsoft Web Browser ActiveX control?

In Access, follow these steps:
* Create a new form
* Add an ActiveX control "Microsoft Web Browser", name it "acxBrowser"
* Add a command button, name it "cmdImport"
* Create the Click event for the button
* Paste the following code

------------------------------------------------------------------------------------
Private Sub cmdImport_Click()

    Const cURL = "http://www.harfang.ch/expert/customer.txt"
    Const cTempName = "~temp~.tmp"
    Const cTempTable = "zttblCustomers"
   
    Dim sngStamp As Single
    Dim strTempFile As String
   
    ' navigate and wait for at most 5s
    Me.acxBrowser.Object.Navigate cURL
    sngStamp = Timer()
    Do While Me.acxBrowser.Object.Busy _
    And sngStamp <= Timer() And Timer() < sngStamp + 5
        DoEvents
    Loop
   
    ' save info
    strTempFile = Left(CurrentDb.Name, InStrRev(CurrentDb.Name, "\")) & cTempName
    Open strTempFile For Output As #1
    Print #1, Me.acxBrowser.Document.documentElement.innerText
    Close #1
   
    ' transfer
    DoCmd.TransferText acImportDelim, , cTempTable, strTempFile, True
   
    ' done!
    Kill strTempFile
    DoCmd.OpenTable cTempTable
   
End Sub
------------------------------------------------------------------------------------

There you go: URL in, Table out. But even double points is waaaaay too cheap ;)

Good Luck
Random Solutions  
 
programming4us programming4us