I have this function working to export to XML. But now I wanted to generate the file every 1500 records of the table STOCK_EXE. I already tried a While (Not .EOF)
with a counter but I lost. Does anyone know the best way to do this?
First Version:
Public Function Function_XML_TEST()
Dim rs As ADODB.Recordset
Dim cn As ADODB.Connection
Dim myXML As MSXML2.DOMDocument
Dim myXSLT As MSXML2.DOMDocument
Dim sSQL As String
Dim CountString As String
Dim LCounter As Integer
Dim iCount As Integer
Set myXML = New MSXML2.DOMDocument
myXML.async = False
myXML.preserveWhiteSpace = False
Set myXSLT = New MSXML2.DOMDocument
myXSLT.async = False
myXSLT.preserveWhiteSpace = False
Set cn = CurrentProject.Connection
Set rs = New ADODB.Recordset
sSQL = "SELECT * FROM STOCK_EXE"
CountString = "SELECT COUNT(*) FROM STOCK_EXE"
iCount = CurrentDb.OpenRecordset(CountString).Fields(0).Value
rs.Open sSQL, cn
iCount = rs.RecordCount 'Determine the number of returned records
With rs
For LCounter = 0 To iCount Step 1500
myXSLT.Load "C:\Users\STOCK_EXE.xslt"
rs.Save myXML, adPersistXML
Call myXML.transformNodeToObject(myXSLT.documentElement, myXML)
If IsNull(Forms!MenuInicial!ProductStatus.Value) Or _
IsNull(Forms!MenuInicial!LpnFacilityStatus.Value) Or _
IsNull(Forms!MenuInicial!InitialAisle.Value) Or _
IsNull(Forms!MenuInicial!FinalAisle.Value) Then
MsgBox ("As Lovs!")
Else
MsgBox ("Criado XML!")
myXML.Save "C:\Users\" & LCounter & "_" & _
Forms!MenuInicial!LpnFacilityStatus.Value & "_" & _
Forms!MenuInicial!InitialAisle.Value & "_" & _
Forms!MenuInicial!FinalAisle.Value & "_DTIM_" & _
Format(Now(), "DDMMYYYY_hhmm") & ".xml"
End If
Next LCounter
End With
rs.Close
cn.Close
End Function
I think I'm close, but it gives me the following error at the point:
rs.OpensSQL, cn
"no value given for one or more required parameters"
Second Version:
Public Function Function_XML_TEST_V1()
Dim rs As ADODB.Recordset
Dim cn As ADODB.Connection
Dim myXML As MSXML2.DOMDocument
Dim myXSLT As MSXML2.DOMDocument
Dim sSQL As String
Dim CountString As String
Dim LCounter As Integer
Dim iCount As Integer
Set myXML = New MSXML2.DOMDocument
myXML.async = False
myXML.preserveWhiteSpace = False
Set myXSLT = New MSXML2.DOMDocument
myXSLT.async = False
myXSLT.preserveWhiteSpace = False
Set cn = CurrentProject.Connection
Set rs = New ADODB.Recordset
CountString = "SELECT COUNT(*) FROM STOCK_EXE_ID"
iCount = CurrentDb.OpenRecordset(CountString).Fields(0).Value
MsgBox ("iCount = " & iCount)
With rs
For LCounter = 1 To iCount Step 1500
MsgBox ("LCounter = " & LCounter)
sSQL = "SELECT * FROM STOCK_EXE_ID" _
& " WHERE STOCK_EXE_ID.ID BETWEEN LCounter and (LCounter + 1500)"
rs.Open sSQL, cn
myXSLT.Load "C:\Path\To\XSLT\STOCK_EXE.xslt"
rs.Save myXML, adPersistXML
Call myXML.transformNodeToObject(myXSLT.documentElement, myXML)
myXML.Save "C:\Path\To\Output\" & LCounter & "_DTIM_" & _
Format(Now(), "DDMMYYYY_hhmm") & ".xml"
rs.Close
cn.Close
Next LCounter
End With
MsgBox ("Passou!")
End Function