Hello friends,
I've created a database with lots of code behind it.
There was not any problem in testing mode, but I have problem now.
The problem is concerned to one cycle which doesn't reaches the end of function and stop the whole function.
The cycle is:
Public Function CommentsToReport_Assessment_Company()
DoCmd.RunSQL "DELETE * FROM Create_Report_Assessment_Company_Comments_Temp;"
DoCmd.RunSQL "INSERT INTO Create_Report_Assessment_Company_Comments_Temp ( RiskNr, Department, Comment ) SELECT Create_Report_Assessment_Company_Comments.RiskNr, Create_Report_Assessment_Company_Comments.Departme nt, Create_Report_Assessment_Company_Comments.Comment FROM Create_Report_Assessment_Company_Comments;"
Dim Db As DAO.Database
Dim rs As DAO.Recordset
Set Db = CurrentDb()
Set rs = Db.OpenRecordset("Create_Report_Assessment_Company _Comments_Temp")
Dim RiskNr As String
Dim Dept As String
RiskNr = ""
Dept = ""
Do While Not rs.EOF
If rs![RiskNr] = RiskNr Then
DoCmd.RunSQL "UPDATE Create_Report_Assessment_Company_CommentsReady_Tem p SET Comment = '" & Dept & "<br />" & "<u>" & rs![Department] & "</u>:" & rs![Comment] & "' WHERE RiskNr = '" & rs![RiskNr] & "';"
RiskNr = rs![RiskNr]
Dept = Dept + "<u>" & rs![Department] & "</u>:" & rs![Comment] & "<br />"
Else
Dept = ""
DoCmd.RunSQL "INSERT INTO Create_Report_Assessment_Company_CommentsReady_Tem p (RiskNr,Comment) VALUES ( '" & rs![RiskNr] & "' , ' <u>" & rs![Department] & "</u>:" & rs![Comment] & "');"
RiskNr = rs![RiskNr]
Dept = Dept + "<u>" & rs![Department] & "</u>:" & rs![Comment] & "<br /> <br />"
End If
rs.MoveNext
Loop
MsgBox "Done!"
End FunctionThe above is the code. This is a function which I call from another function.
I put 407 records in the recordset. The cycle starts and after 37 times it stops. I saw that if I comment a code, I mean to remove the SQL code there is not problem, so the problem is with it.
Do you have any ideas what can cause the problem?
Thank you in advance,
Best wishes