Results 1 to 4 of 4
  1. #1
    free_style is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2011
    Posts
    4

    Recordset cycle problem

    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

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    It seems you have a space in the middle of Temp --> Tem p

    DoCmd.RunSQL "INSERT INTO Create_Report_Assessment_Company_CommentsReady_Tem p (RiskNr,Comment)

    You can insert some Debug.print statements to see exactly what some of the SQL statements are before you run the code.

  3. #3
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    if orange's suggestion does not work can you post a sample database with garbage data that can duplicate the error. Without seeing the dataset and looking at where it's breaking down and why it's going to be very difficult to tell you what's wrong.

  4. #4
    free_style is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2011
    Posts
    4
    Hello guys,

    I solved the problem!

    It wasn't the problem with Tem p. That was because of copying from the VBA to the forum directly. In the original version of the code is Temp.

    However, the problem was that I import data (Comments) from one Excel file to Access and then work with them. Anyway, there was happened an SQL injection, caused by the comments. In several of theme there was ' , because something like this: "I haven't been in Paris!". This apostrophe (quote) it happens SQL injection. It was really hard to define this such as problem.

    It is not possible to validate the date while entering, so I get the values from rs![Comment] for every record in the recordset and put it into variable. After that I use REPLACE function to replace all the forbidden characters, such as ' (you may change it with double quote - '' ) or SELECT, UPDATE, etc. You know this expressions....

    Thank you for your fast answers and for you activity!
    Best wishes

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Setting Form Recordset Problem
    By Gray in forum Forms
    Replies: 7
    Last Post: 05-23-2011, 07:49 AM
  2. Recordset Findfirst Problem
    By ColPat in forum Programming
    Replies: 6
    Last Post: 07-22-2010, 04:34 AM
  3. Cycle Text Boxes with a For next loop
    By Gary in forum Programming
    Replies: 3
    Last Post: 07-20-2010, 09:32 AM
  4. Replies: 1
    Last Post: 11-13-2009, 03:03 AM
  5. Cycle Time
    By Dargo in forum Forms
    Replies: 5
    Last Post: 02-26-2009, 05:14 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums