Loop issue

F&s anaylst

Active Member
Joined
Oct 9, 2008
Messages
277
HI All,

i have macro that will loop through and upload data into access database but for some reason when it hits row 75 it automatically runs out of the loop and does complete the loop, any idea why this would happen?

It is called by through the below code
HTML:
Sub ReportingType()
Dim Files As Integer
On Error Resume Next
Files = WorksheetFunction.Find("Agent Group Event by Period", MyFile)
If Files > 0 Then
Call Agent_Group_Event_by_Period
On Error GoTo 0
Exit Sub
Else
....additional code here
End If
End Sub

it then runs into the below code but if the reports has more than 75 rows it gets to from row 3 to 75 succesfully but on row 76 when it gets to this part
DB.Execute SQLtext
it runs back the above sub on this line but it doesn't actually finish the below sub
On Error GoTo 0

HTML:
Sub Agent_Group_Event_by_Period()
Dim LastRow As Integer
Dim SQLtext As String
Dim DB As Database
Dim RS As Recordset
Set DB = OpenDatabase(Sheet1.Range("DBAddress").Value)
Set RS = DB.OpenRecordset("tbl_Agent_Group_Event_by_Period", dbOpenTable)
Workbooks.Open (MyFile)
Tempfile = ActiveWorkbook.Name
ActiveWorkbook.Sheets("Data Sheet").Select
 
Range("b7").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Copy
 
Workbooks(TemPlate).Activate
ActiveWorkbook.Sheets("Agent Group Event by Period").Select
ActiveSheet.Range("b3").PasteSpecial xlPasteValues
Application.CutCopyMode = False
LastRow = Range("b3").End(xlDown).Row
For Rows = 3 To LastRow
'table name
SQLtext = "INSERT INTO [tbl_Agent_Group_Event_by_Period] "
'column names
SQLtext = SQLtext & "([Agent ID],[Agent name], [login date/time], "
SQLtext = SQLtext & "[logout date/time], [Total shift time], [Idle time],"
SQLtext = SQLtext & "[Average ringing time], [Total ACD calls],"
SQLtext = SQLtext & "[ACD Total Time],[AHT],[Total outbound time],"
SQLtext = SQLtext & "[Outbound calls],[Total make busy time],"
SQLtext = SQLtext & "[Average make busy time],[Make busy counts],"
SQLtext = SQLtext & " [Total DND time], [Average DND time],[Requeues],"
SQLtext = SQLtext & " [DND counts])"
'values to upload into table
SQLtext = SQLtext & " VALUES ('" & Cells(Rows, 2).Value & "', '"
SQLtext = SQLtext & Cells(Rows, 3).Value & "', '" & Cells(Rows, 4).Value
SQLtext = SQLtext & "', '" & Cells(Rows, 5).Value & "', '"
SQLtext = SQLtext & Format(Cells(Rows, 6).Value, "Long Time") & "', '"
SQLtext = SQLtext & Format(Cells(Rows, 7).Value, "Long Time") & "', '"
SQLtext = SQLtext & Format(Cells(Rows, 8).Value, "Long Time") & "', '"
SQLtext = SQLtext & Cells(Rows, 9).Value & "', '"
SQLtext = SQLtext & Format(Cells(Rows, 11).Value, "Long Time") & "', '"
SQLtext = SQLtext & Format(Cells(Rows, 12).Value, "Long Time") & "', '"
SQLtext = SQLtext & Format(Cells(Rows, 18).Value, "Long Time") & "', '"
SQLtext = SQLtext & Cells(Rows, 19).Value & "', '"
SQLtext = SQLtext & Format(Cells(Rows, 23).Value, "Long Time") & "', '"
SQLtext = SQLtext & Format(Cells(Rows, 24).Value, "Long Time") & "', '"
SQLtext = SQLtext & Cells(Rows, 25).Value & "', '"
SQLtext = SQLtext & Format(Cells(Rows, 26).Value, "Long Time") & "', '"
SQLtext = SQLtext & Format(Cells(Rows, 27).Value, "Long Time") & "', '"
SQLtext = SQLtext & Cells(Rows, 28).Value & "', '"
SQLtext = SQLtext & Cells(Rows, 29).Value & "');"
'run sql call
DB.Execute SQLtext
 
    If LastRow = Rows Then
    Sheet2.Range("$B$3:$AD$" & LastRow).ClearContents
    End If
 
Next Rows
 
RS.Close
Set RS = Nothing
DB.Close
Set DB = Nothing
End Sub

Any ideas what is happening here as the data within the source location doesn't change its structure or format in any way. If you need more info let me know
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.

Forum statistics

Threads
1,224,583
Messages
6,179,681
Members
452,937
Latest member
Bhg1984

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top