Automatically upload html files to MS access (1 Viewer)

talha

New member
Local time
Yesterday, 19:23
Joined
May 9, 2020
Messages
22
Hi,

I have about 100 files (.html). Is there a way to automatically upload data from these files without manually opening and copying it into the MS access table?

Thanks
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 17:23
Joined
Oct 29, 2018
Messages
21,528
Do you mean like parsing data or simply saving a copy of the files in the database?
 

talha

New member
Local time
Yesterday, 19:23
Joined
May 9, 2020
Messages
22
Do you mean like parsing data or simply saving a copy of the files in the database?
copying all data from these files into a single MS Access table
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 08:23
Joined
May 7, 2009
Messages
19,246
maybe you will need vba to Loop through each html file and get it's html text before saving to table:
to get the html content of a textfile, you can write this vba:
Code:
Public Function GetTextFileContent(ByVal filePath As String) As String
    Dim fileContent As String
    Dim fileHandle As Integer
   
    If Len(Dir$(filePath)) = 0 Then
        Exit Function
    End If
   
    ' Open the text file for reading
    fileHandle = FreeFile()
    Open filePath For Input As #fileHandle
   
    ' Read the content of the file into a variable
    fileContent = Input$(LOF(fileHandle), fileHandle)
   
    ' Close the file
    Close #fileHandle
   
    ' Print or manipulate the file content as needed
    'Debug.Print fileContent
    GetTextFileContent = fileContent
End Function

then save it to your Long Text field on your table:
Code:
With CurrentDb.CreateQueryDef("", "insert into yourTable(textField) select [p1];")
    .Parameters(0) = GetTextFileContent(theTextfile)
    .Execute
End With
 
Last edited:

ebs17

Well-known member
Local time
Today, 02:23
Joined
Feb 7, 2020
Messages
1,971
The first step you should be interested in is the structure within the HTML file if you want to import content. Closing your eyes and pressing the button will usually go wrong.
If there is just a simple table, it can be very simple.
Code:
Sub import2()
    Dim con As Object
    Dim sSQL As String
    Set con = CreateObject("ADODB.Connection")
    con.Open _
            "Provider=Microsoft.ACE.OLEDB.12.0;" & _
                                                 "Data Source=E:\tests\htmlimport\bsp.htm;" & _
                                                 "Extended Properties=""HTML Import;HDR=YES;IMEX=1"";"
    sSQL = "INSERT INTO [" & CurrentDb.Name & "].MyData(ID, Lastname) SELECT ID, Lastname FROM [Test Data]"
    con.Execute sSQL
    con.Close
    Set con = Nothing
End Sub
A loop over several files shouldn't be a problem.
 

Attachments

  • bsp.zip
    425 bytes · Views: 29

Users who are viewing this thread

Top Bottom