Solved

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

Posted on 2014-11-19
4
206 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

743 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

12 Experts available now in Live!

Get 1:1 Help Now