Results 1 to 3 of 3
  1. #1
    Puebles is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Sep 2013
    Location
    Lansing, MI
    Posts
    14

    Query works in Access but not with .Execute, yet there is no error.

    Greetings,



    I am trying to replace a large volume of slow moving code that goes through each record in a table of key words and phrases (currently 32 records and subject to change) and searches the comment field of another table. When a match is found the field [ExcludeMe] is incremented by 1. This code below works exceptional fast and the [ExlucdeMe] field is properly updated when the SQL is run in the Accesss Query builder. However, when run in this code, there is no error, but the [ExcludeMe] field is not updated.

    Code:
    Do While Not rs5.EOF
        strExcludeThisWord = rs5![ExcludeThisWord]
        strSetToZero = " UPDATE tblComments SET tblComments.ExcludeMe = 0 WHERE (([AFS_NUMBER]>1)); "
        db.Execute strSetToZero, dbFailOnError
        strExcludeThese = "UPDATE tblComments SET tblComments.ExcludeMe = IIf(InStr(1,[comment],'" & strExcludeThisWord & "'),[ExcludeMe]+1,[ExcludeMe]) WHERE (((tblComments.AFS_NUMBER)>1)); "
    '    MsgBox (strExcludeThese)
        db.Execute strExcludeThese, dbFailOnError
        rs5.MoveNext
    Loop
    Thank you in advance.

  2. #2
    Puebles is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Sep 2013
    Location
    Lansing, MI
    Posts
    14
    Found it. The reset of the [ExcludeMe] field is inside the loop. It needs to be outside/before the loop.

  3. #3
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    make your msgbox (strExcludethese) a debug.print strExcludeThese, cut and paste the code into a query designer, then try to run it, see what kind of error it generates and go backward from there.

    This snippet of your code isn't much to go on but I think your code:

    Code:
    strSetToZero = " UPDATE tblComments SET tblComments.ExcludeMe = 0 WHERE (([AFS_NUMBER]>1)); " 
        db.Execute strSetToZero, dbFailOnError
    Should be outside your loop, because what you're doing right now is setting your excludeme value to 0 for every record you process then incrementing it by 1 only if it meets an instr criteria. so I would think that the last record you're processing does not meet the criteria so in essence you're setting your value to zero, then adding zero to 0 then adding a maximum of 1 for every record in your database so the most you could possibly end up with is 1, but in all likelyhood it's going to be a 0 because a vast majority of your records will not meet the criteria.

    Code:
    strSetToZero = " UPDATE tblComments SET tblComments.ExcludeMe = 0 WHERE (([AFS_NUMBER]>1)); " 
    db.Execute strSetToZero, dbFailOnError     
        
    Do While Not rs5.EOF     strExcludeThisWord = rs5![ExcludeThisWord]     
         strExcludeThese = "UPDATE tblComments SET tblComments.ExcludeMe = IIf(InStr(1,[comment],'" & strExcludeThisWord & "'),[ExcludeMe]+1,[ExcludeMe]) WHERE (((tblComments.AFS_NUMBER)>1)); " 
         'MsgBox (strExcludeThese)     
         db.Execute strExcludeThese, dbFailOnError     
         rs5.MoveNext 
    Loop

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

Similar Threads

  1. Access2007 error 3075 execute SELECT
    By candide in forum SQL Server
    Replies: 1
    Last Post: 04-24-2013, 08:31 AM
  2. Replies: 1
    Last Post: 06-21-2012, 07:58 PM
  3. Replies: 3
    Last Post: 03-15-2012, 03:42 PM
  4. Replies: 2
    Last Post: 02-07-2012, 08:38 PM
  5. db.Execute Error 3061
    By JimG in forum Programming
    Replies: 5
    Last Post: 05-17-2010, 09:34 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