Import spec ? (1 Viewer)

gbanks

Registered User.
Local time
Today, 01:28
Joined
Feb 9, 2000
Messages
161
I'm importing a html report into Access97. I was able to import all the fields I needed which are field1, field2 and field25. I saved this as an import specifaction. The problem I came across was that the next month the html doc changed the number of fields. I was able to import field1 and 2 which didn't change. But field 25 which was a total field was now field 26. So oviously is imported field 25 which is what the specifaction stated. My question is I only need the first second and last fields of this report. Is there any way to tell access this? Or is there another way to get this data into an access table? Thanks...
 

Travis

Registered User.
Local time
Yesterday, 17:28
Joined
Dec 17, 1999
Messages
1,332
Code:
Public Sub XMLDataBase(ByVal sFile As String)
    Dim rstXML As ADODB.Recordset
    Dim rstImportTable As ADODB.Recordset
    Dim cnnIT As ADODB.Connection
    
    'Set the connection object to the current MDB connection
    Set cnnIT = CurrentProject.Connection
    
    'Set RecordSets for creation
    Set rstImportTable = New ADODB.Recordset
    Set rstXML = New ADODB.Recordset
    
    'Open the table to hold the imported records
    rstImportTable.Open "Select * [ImportTableName]", cnnIT, adOpenDynamic, adLockOptimistic
    
    'Using ADO Open the XML file as a RecordSet
    'CursorLocation must be Client Side
    rstXML.CursorLocation = adUseClient
    rstXML.Open sFile, , , , adCmdFile
    If rstXML.RecordCount > 0 Then
        rstXML.MoveFirst
        'Loop through all of the XML records.
        Do While Not rstXML.EOF
            rstImportTable.AddNew
            'Set your first field
            rstImportTable.Fields("FirstField") = rstXML.Fields(0)
            'Set your second field
            rstImportTable.Fields("SecondField") = rstXML.Fields(1)
            'Set your last field
            rstImportTable.Fields("LastField") = rstXML.Fields(rstXML.Fields.Count - 1)
            'Save the record
            rstImportTable.Update
            rstXML.MoveNext
        Loop
    End If
    
    rstImportTable.Close
    Set rstImportTable = Nothing
    rstXML.Close
    Set rstXML = Nothing

End Sub
 

Users who are viewing this thread

Top Bottom