I am probably using the wrong terminology, but here is what is happening. I have a DO loop that is taking data from one sheet and data from an SQL call and outputing it to another sheet. On the 6th time through (and I am watching with the debugger stepping through each line of code) the code jumps from the normal lines of code to one of my UDFs. The thread stays in the UDF and eventually I have to restart Excel.
The code snippet is included below. I am including the entire first part of the DO loop since there are some SQL calls that I believe are causing the issue. Note the commented line near the end. This is the line where the thread jumps off to the UDF. If I comment this line, then the thread jumps the the UDF on the next line.
Do While Worksheets("Bucket").Cells(j + 4, 1).Value <> ""
j = j + 1
FindPartFlag = 0
buf = Worksheets("Bucket").Cells(j + 3, 3).Value
sqlQuery = "SELECT Count(" & Module3.DBPart & ") FROM sheet1 Where " & Module3.DBPart & "='" & Worksheets("Bucket").Cells(j + 3, 3).Value & "'"
On Error Resume Next
rs.Open sqlQuery
FindPartFlag = rs(0)
rs.Close
If FindPartFlag > 0 Then
sqlQuery = "SELECT * FROM sheet1 WHERE Field1 = '" & Worksheets("Bucket").Cells(j + 3, 3).Value & "'"
On Error Resume Next
rs.Open sqlQuery
Worksheets("NFG").Cells(j + 1, 1).Value = LCase(rs(1))
buf1 = LCase(rs(17))
If Trim(LCase(rs(17))) = "v" Then
Worksheets("NFG").Cells(j + 1, 1).Font.Color = vbGreen
Else
Worksheets("NFG").Cells(j + 1, 1).Font.Color = vbRed
End If
Worksheets("NFG").Cells(j + 1, 2).Value = Worksheets("Bucket").Cells(j + 3, 2).Value
buf1 = Module3.get_gap_k("n")
'Worksheets("NFG").Cells(j + 1, 3).Value = Worksheets("Bucket").Cells(j + 3, 7).Value
Worksheets("NFG").Cells(j + 1, 4).Value = rs(3)
(here are more lines of the same kind of output to Worksheets("NFG")...., then the end of the loop)
I can include the UDF too, it is only about a dozen lines of code. But right now, I don't think the issue is what is in the UDF, only that the thread is being directed there.
Hopefully I have described this problem properly.
Thanks for any help
Pat
The code snippet is included below. I am including the entire first part of the DO loop since there are some SQL calls that I believe are causing the issue. Note the commented line near the end. This is the line where the thread jumps off to the UDF. If I comment this line, then the thread jumps the the UDF on the next line.
Do While Worksheets("Bucket").Cells(j + 4, 1).Value <> ""
j = j + 1
FindPartFlag = 0
buf = Worksheets("Bucket").Cells(j + 3, 3).Value
sqlQuery = "SELECT Count(" & Module3.DBPart & ") FROM sheet1 Where " & Module3.DBPart & "='" & Worksheets("Bucket").Cells(j + 3, 3).Value & "'"
On Error Resume Next
rs.Open sqlQuery
FindPartFlag = rs(0)
rs.Close
If FindPartFlag > 0 Then
sqlQuery = "SELECT * FROM sheet1 WHERE Field1 = '" & Worksheets("Bucket").Cells(j + 3, 3).Value & "'"
On Error Resume Next
rs.Open sqlQuery
Worksheets("NFG").Cells(j + 1, 1).Value = LCase(rs(1))
buf1 = LCase(rs(17))
If Trim(LCase(rs(17))) = "v" Then
Worksheets("NFG").Cells(j + 1, 1).Font.Color = vbGreen
Else
Worksheets("NFG").Cells(j + 1, 1).Font.Color = vbRed
End If
Worksheets("NFG").Cells(j + 1, 2).Value = Worksheets("Bucket").Cells(j + 3, 2).Value
buf1 = Module3.get_gap_k("n")
'Worksheets("NFG").Cells(j + 1, 3).Value = Worksheets("Bucket").Cells(j + 3, 7).Value
Worksheets("NFG").Cells(j + 1, 4).Value = rs(3)
(here are more lines of the same kind of output to Worksheets("NFG")...., then the end of the loop)
I can include the UDF too, it is only about a dozen lines of code. But right now, I don't think the issue is what is in the UDF, only that the thread is being directed there.
Hopefully I have described this problem properly.
Thanks for any help
Pat
Last edited: