Stang70Fastback
Registered User.
- Local time
- Today, 17:54
- Joined
- Dec 24, 2012
- Messages
- 132
Hello all. I am trying to import an HTML table into Access. Someone suggested I use ACE/Jet, which I got working with the following code:
However, the original goal was for this to pull straight from the web page - not from a copy of the web page saved locally. Does anyone know if this is possible? I tried the obvious use of a URL rather than a local directory, but that throws a "read only" error suggesting an unrecognized file extension. Is it possible to do what I am trying to do?
Private Sub Command0_Click()
Const LocalTableName = "EMPLOYEES"
Dim con As Object, rstHtml As Object, fld As Object, _
cdb As DAO.Database, rstAccdb As DAO.Recordset, _
recCount As Long
Set con = CreateObject("ADODB.Connection")
con.Open _
"Provider=Microsoft.ACE.OLEDB.12.0;" & _
"Data Source=C:\Users\Desktop\EMPLOYEES.htm;" & _
"Extended Properties=""HTML Import;HDR=YES;IMEX=1"";"
Set rstHtml = CreateObject("ADODB.Recordset")
rstHtml.Open "SELECT * FROM [EMPS_VIEW_BUS_TRAINING Report]", con
Set cdb = CurrentDb
cdb.Execute "DELETE FROM [EMPLOYEES]", dbFailOnError
Set rstAccdb = cdb.OpenRecordset("EMPLOYEES", dbOpenTable)
recCount = 0
Do While Not rstHtml.EOF
recCount = recCount + 1
rstAccdb.AddNew
For Each fld In rstHtml.Fields
rstAccdb.Fields(Trim(fld.Name)).Value = Trim(fld.Value)
Next
Set fld = Nothing
rstAccdb.Update
rstHtml.MoveNext
Loop
rstAccdb.Close
Set rstAccdb = Nothing
Set cdb = Nothing
rstHtml.Close
Set rstHtml = Nothing
con.Close
Set con = Nothing
Debug.Print recCount & " record(s) imported"
End Sub
However, the original goal was for this to pull straight from the web page - not from a copy of the web page saved locally. Does anyone know if this is possible? I tried the obvious use of a URL rather than a local directory, but that throws a "read only" error suggesting an unrecognized file extension. Is it possible to do what I am trying to do?