2015-10-29 37 views
0

这个子程序运作良好,但现在我得到一个“循环离不开”错误:“你不循环”错误

Sub Upload_earned_pto() 

Dim conn As New ADODB.Connection 
Dim iRowNo As Integer 
Dim UID, PW, s1, s3, s5, s7 As String 
Dim s4, s6 As Date 
Dim s2 As Double 


UID = ThisWorkbook.Sheets("Sheet1").Range("A1") 
PW = ThisWorkbook.Sheets("Sheet1").Range("B1") 


With Sheets("Monthly Adjustments") 

    'Open a connection to SQL Server 
    conn.Open "Provider=SQLOLEDB.1;Password=" & PW & ";Persist Security Info=True;User ID=" & UID & ";Initial Catalog=TESTDB;Data Source=TESTSRV;Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation ID=MPL-DEV1;Use Encryption for Data=False;Tag with column collation when possible=False" 

    'Skip the header row 
    iRowNo = 8 

    'Loop until empty cell in batch_skey 
    Do Until .Cells(iRowNo, 1) = "" 
     If Rows(iRowNo).Hidden = True Then 
      iRowNo = iRowNo + 1 
     ElseIf Rows(iRowNo).Hidden <> True Then 

     s1 = .Cells(iRowNo, 1) 
     s2 = .Cells(iRowNo, 2) 
     s3 = .Cells(iRowNo, 3) 
     s4 = .Cells(iRowNo, 4) 
     s5 = .Cells(iRowNo, 5) 
     s6 = .Cells(iRowNo, 6) 
     s7 = .Cells(iRowNo, 7) 

'Generate and execute sql statement to export the excel rows to SQL Server table 
conn.Execute "insert into dbo.pto_transactions values ('" & s1 & "', '" & s3 & "' 

, '" & s6 & "', '" & s2 & "', '" & s4 & "', '" & s5 & "', '" & s7 & "')" 
     iRowNo = iRowNo + 1 
    Loop 

    MsgBox "PTO Transactions Successfully Sent." 

    conn.Close 
    Set conn = Nothing 

End With 
+2

你错过了一个'end if' –

+0

我是白痴!错过了我的结局如果! –

+0

@ScottCraner谢谢你!从字面上看,只是注意到它,并发布我的评论。 –

回答

0

缺少的结束如果。感谢@ScottCraner指出。