HTTP connections in VBA for Access

Programming, for all ages and all languages.
Post Reply
Schol-R-LEA

HTTP connections in VBA for Access

Post by Schol-R-LEA »

I have what at first seemed to be a straightforward contract, but which increasingly seems difficult or impossible to complete. The client has an existing A2k database which includes a table of websites related to their own. The client wishes to be able to automatically generate a report which shows which links are either inactive, or have changed so that they no longer contain certain keywords. They also want to be able to list those which are still valid, as well.

My planned design was to use a VBA script which would go something like this:

Code: Select all

 for each record in the table,
      extract the URL (currently stored in a memo)
      connect to the website's TCP port 80
      if server returns an error message (404, 501, etc.)
              store the URL and error message in a temporary table
      else
              scan the page for the keyword
              if the keyword is not found
                     store the URL and missed word in a temp table
 generate report from the temp table(s)
Since I need to get the HTTP error codes, and since I mean to read in the pages without parsing the HTML, I cannot see any feasible way to do this except by connecting to the TCP port directly. However, as far as I can determine, VBA/Access simply doesn't have any facility for that; AFAICT, the closest thing that it supports is opening a web browser from a given hyperlink, without any way of reading the results in Access.

I think it would be trivial to use Perl or Java to handle the connections and store the results back to the database, but since the client wants the reports done in Access, it would mean a two step process which may not be acceptable. I don't see any way to do it in VB 6.0, either, though I have not pursued that line of inquiry too deeply. I am certain it could be done in VB.NET, but neither I nor the client have been using it to date, and we would rather avoid adding any new development tools to those already in use. In any case, using VB would mean using Crystal Reports instead of the Access Report Generator, which may not be acceptable to the client.

I keep thinking I have overlooked something important. I have already taken longer with this assignment than I should have, and the client is understandably displeased. Even a negative answer, if definitive, would allow me to proceed, even if it means discontinuing the contract.
Therx

Re:HTTP connections in VBA for Access

Post by Therx »

Could you write an ActiveX control in something like C to find the error code or what ever and then import into the VB app or VBA.

This is a guess as I haven't used VB or ActiveX for ages.

Hope you find the answer you need

Pete
Tim

Re:HTTP connections in VBA for Access

Post by Tim »

I don't know Access, but can you use arbitrary functions from DLLs? If so, the WinInet functions would be very useful. They should be documented at http://msdn.microsoft.com/library/; search for InternetOpen and browse from there.

Or, as Pete points out, you could write a COM server to do the work. An ActiveX control would do, or a simple COM Automation server with one method (DownloadPageAndScanForKeyword) would be easier. Either would require C++ or VB. (It's technically possible to write COM code in C, but it's far more work than necessary.)
User avatar
df
Member
Member
Posts: 1076
Joined: Fri Oct 22, 2004 11:00 pm
Contact:

Re:HTTP connections in VBA for Access

Post by df »

in your references select mswinsock.ocx (microsoft winsock control 6.0 sp5)... that can connect to tcp or udp. works very simply.
-- Stu --
Schol-R-LEA

Re:HTTP connections in VBA for Access

Post by Schol-R-LEA »

Thank you; all of these answers tell me what I needed to know. Ironically, however, it seems the project need not be done in Access after all... oh, well.
Post Reply