Solved

How to extract data from a webpage and enter into an Access Database?

Posted on 2014-11-19
4
211 Views
Last Modified: 2014-11-20
I have a Microsoft Access 2010 Database with a table and a form to read data from a webpage.
When I enter a number into the form, the form must have code to open the corresponding webpage and read a range of data from fields in the web page into the table in the database.
I only want the pages as I enter the numbers (SAQA QUAL ID = fugures long). I don't want the whole website as the information may change any time.
Typical page addresses are
http://allqs.saqa.org.za/showQualification.php?id=62322
http://allqs.saqa.org.za/showQualification.php?id=59769 
Note the 5 digit number at the end. So I think that will be simple to just add the number to the first part of the url. But what then?
I want the attach the VBA code to the provided button on the form.
Database is attached
Where and how should I start?
0
Comment
Question by:Fritz Paul
  • 2
  • 2
4 Comments
 
LVL 49

Accepted Solution

by:
Gustav Brock earned 500 total points
ID: 40452638
You can use the function below to download the page and save as, say, "saqa.html"
This file you can attach via "External Data". Select More, HTML Document.
The wizard opens and you will have listed all the tables inside the document.
It is most likely the SAQA4 you will need. Finish the wizard and you the table attached.
However, it is in spreadsheet style so you are on your own how to proceed from here.

To read another page, you can download that page and overwrite the file linked to.
Option Compare Database
Option Explicit

Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" ( _
    ByVal pCaller As Long, _
    ByVal szURL As String, _
    ByVal szFileName As String, _
    ByVal dwReserved As Long, _
    ByVal lpfnCB As Long) _
    As Long


Public Function DownloadFile( _
    ByVal strURL As String, _
    ByVal strLocalFilename As String) _
    As Long
  
' Download file or page with public access from the web.
' 2004-12-17. Cactus Data ApS, CPH.

' Usage, download a file:
' lngRet = DownloadFile("http://www.databaseadvisors.com/Graphics/conf2002/2002ConferencePicsbySmolin/images/dba02smolin27.jpg", "c:\happybassett.jpg")
'
' Usage, download a page:
' lngRet = DownloadFile("http://www.databaseadvisors.com/conf2002/conf200202.asp", "c:\dbaconference.htm")

' Returns 0 if success, error code if not.
' Error codes:
' -2146697210 "file not found".
' -2146697211 "domain not found".

' Limitation.
' Does not check if local file was created successfully.

    Dim lngRetVal As Long
      
    lngRetVal = URLDownloadToFile(0, strURL & vbNullChar, strLocalFilename & vbNullChar, 0, 0)
    
    DownloadFile = lngRetVal
  
End Function

Open in new window

saqa.PNG/gustav
0
 

Author Comment

by:Fritz Paul
ID: 40452843
I will try that thanks. Many thanks.
0
 

Author Closing Comment

by:Fritz Paul
ID: 40454471
Thanks Gustav,
I got it in Excel and I know how to read from Excel.
Fritz
0
 
LVL 49

Expert Comment

by:Gustav Brock
ID: 40454474
OK, great.

/gustav
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Suggested Solutions

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

861 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

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now