Automatically upload html files to MS access (1 Viewer)

talha

New member
Local time
Today, 04:33
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
 
Do you mean like parsing data or simply saving a copy of the files in the database?
 
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
 
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:
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

Users who are viewing this thread

Back
Top Bottom