Execute method does not consistently execute all c

2019-08-11 21:41发布

问题:

I have below procedure to execute multiple command text to update an Access Table from Excel.

Private Sub LogToDBMult(ParamArray sqlstr())

    Dim con As Object, i As Integer

    Set con = getCon()

    With con

        For i = LBound(sqlstr) To UBound(sqlstr)
            If sqlstr(i) <> "" Then
                .Execute sqlstr(i)
                Sleep 1000 '/* this is an API call */
                DoEvents
            End If
        Next

        .Close
        Set con = Nothing
    End With

End Sub

Private Function getCon() As Object

    Dim oCon As Object
    Dim sCon As String

    sCon = "Provider=Microsoft.ACE.OLEDB.12.0;" & _
           "Data Source=" & dataSource & ";" & _
           "Persist Security Info=False;"

    '/* dataSource just contains the path declared publicly */

    Set oCon = CreateObject("ADODB.Connection")

    oCon.Open sCon
    Set getCon = oCon

End Function

Now, below are some of the sqlstr I pass in the procedure.

xlSource1 = "[Excel 12.0;HDR=YES;Database=" & ThisWorkbook.fullname & "].[Sheet1$] "
xlSource2 = "[Excel 12.0;HDR=YES;Database=" & ThisWorkbook.fullname & "].[Sheet2$] "

qry1 = "INSERT INTO dbo_table1 (F1,F2,F3,F4,F5,F6) "
qry1 = qry1 & "SELECT F1,F2,F3,F4,F5,F6 From " & xlSource1
qry1 = qry1 & "WHERE F1 <> '';"

qry2 = "INSERT INTO dbo_table2 (F1,F2,F3,F4,F5) "
qry2 = qry2 & "SELECT F1,F2,F3,F4,F5 From " & xlSource2
qry2 = qry2 & "WHERE F1 <> '';"


'/* I have other similar command text, I just listed 2 */

'/* then calling the procedure like: */

LogToDBMult qry1, qry2 '/* up to how many command text I have */

Now this works great and the application I created for a few users worked.
However, there are instances that some command text aren't executed.
And so some tables get's updated and some do not. Now, what am I missing?
What do I need to do to make sure all command text are executed?