+ Reply to Thread
Results 1 to 11 of 11

Problem in loop for recordset

  1. #1
    Forum Contributor
    Join Date
    02-20-2009
    Location
    bristol
    MS-Off Ver
    Excel 2003
    Posts
    883

    Problem in loop for recordset

    Hi guys

    I am getting a problem in the loop below. It doesn't display me each person's record. Can anyone please solve my problem.

    Please Login or Register  to view this content.
    Thanks
    Aman

  2. #2
    Forum Contributor daksh1981's Avatar
    Join Date
    04-15-2009
    Location
    India
    MS-Off Ver
    2003 & 2007
    Posts
    110

    Re: Problem in loop for recordset

    Try to use absolute recordset field name instead of index number. For example rs.fields(“User Name”).
    I am still a learner.

  3. #3
    Forum Contributor
    Join Date
    02-20-2009
    Location
    bristol
    MS-Off Ver
    Excel 2003
    Posts
    883

    Re: Problem in loop for recordset

    Hi

    I think there is no problem of field names as the code works fine but it displays the result of only one person. Suppose one person has done 10 letters and 2nd person has done 5 letters then the report will display the username,total letters and total time taken to do those letters for one person only and will not display anything for the 2nd person.

    I hope anyone can help me in this.

    Thanks

  4. #4
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482

    Re: Problem in loop for recordset

    Hard to tell as you have not posted all the relevant code but a guess would be that the output sheet being references as ws is not the activesheet where J is being defined.
    Cheers
    Andy
    www.andypope.info

  5. #5
    Forum Contributor
    Join Date
    02-20-2009
    Location
    bristol
    MS-Off Ver
    Excel 2003
    Posts
    883

    Re: Problem in loop for recordset

    Hi

    Please find below the complete code and put me in the right direction.

    Please Login or Register  to view this content.
    Thanks

  6. #6
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482

    Re: Problem in loop for recordset

    Is Sheet3 the active worksheet?

    try using the same sheet object
    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    02-20-2009
    Location
    bristol
    MS-Off Ver
    Excel 2003
    Posts
    883

    Re: Problem in loop for recordset

    After writing ws instead of activesheet, there is no difference in the output. Again one person's record gets displayed and other users records are again not displayed.

    I think the loop runs only once thats why only first person's record gets printed. Please can you read the code inside loop again and guide me in this.

  8. #8
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482

    Re: Problem in loop for recordset

    Without the data file it is impossible for use to guess what is happening.

    What happens when you step through the code line by line.
    What are the values of J. Are they correct.

    Does the record set really return more than 1 person.
    Try adding some debug.print line so you know for sure data is being missed from the worksheet

  9. #9
    Forum Contributor
    Join Date
    02-20-2009
    Location
    bristol
    MS-Off Ver
    Excel 2003
    Posts
    883

    Re: Problem in loop for recordset

    When I write :

    a=rs.recordcount

    then it displays me the result -1.

    Please Login or Register  to view this content.

  10. #10
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482

    Re: Problem in loop for recordset

    don't you need to move through the record set before the recordcount returns meaningful values.

    why not for debugging simple debug.print all the information.

  11. #11
    Forum Contributor
    Join Date
    02-20-2009
    Location
    bristol
    MS-Off Ver
    Excel 2003
    Posts
    883

    Re: Problem in loop for recordset

    Hi Andy

    There is a problem in the loop only which displays first record only. As if i write the following code then everything works fine :

    Please Login or Register  to view this content.
    Thanks a lot anyway for your help.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1