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
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
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
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
it runs back the above sub on this line but it doesn't actually finish the below subDB.Execute SQLtext
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