Reputation: 41
This subroutine was working well but now I'm getting a "Loop without Do" error:
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
Upvotes: 1
Views: 4963
Reputation: 41
Missing the End If. Thanks to @ScottCraner for pointing it out.
Upvotes: 1