Results 1 to 7 of 7
  1. #1
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615

    Puzzling error in VBA db.execute statement

    Using A2010 in Windows 7.



    This one really has me stumped. Can anyone see anything wrong with this statement?

    currentdb.Execute "Update Text_File_FF set Statement_text = replace(Statement_Text,' ',' ')",dbfailonerror"
    or
    currentdb.Execute "Update Text_File_FF set Statement_text = replace(Statement_Text,"" "","" "")",dbfailonerror

    I want to change all occurrances of a double space in the Statement_Text field to a single spaces. Statement_Text is Text 200 data type.

    It worked fine in A2003 on Windows XP, but now both versions are giving me the "data type mismatch in criteria expression" error.
    (To test, I used "A" and "B" instead of blanks - same error)

    I checked all the names, and they are OK - I get different errors otherwise.

    Any ideas?

    Thanks.

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    I removed the dbfailonerror parameter and the update works.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    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,870
    The quote after dbFailOnError seems extraneous.

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Maybe that was a post typo, because I still got error even after correcting for that.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    amrut is offline Expert
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2012
    Location
    India
    Posts
    616
    currentdb.Execute "Update Text_File_FF set Statement_text = replace(Statement_Text,"" "","" "")",dbfailonerror
    The second one is correct but you have used single space for both the parameters in replace function, the first should be double space.
    Code:
    CurrentDb.Execute "UPDATE Text_File_FF SET Statement_text = Replace(Statement_text,""  "","" "")", dbFailOnError
    But in that case the query will not update but should not throw an error.

  6. #6
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Good morning all -

    I found the problem and the solution.

    After looking at numerous results from a google search on this issue, I found a posting that said Replace does not like Null as its first argument; the VBA help confirms that. (Talk about a misleading error message!)


    I changed the code to:

    currentdb.Execute "Update Text_File_FF set Statement_text = replace(nz(Statement_Text,''),' ',' ')", dbfailonerror

    and it works without a problem.

    Thanks!

  7. #7
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    amrut, I am sure OP used double space but the forum programming does not allow repetitive spacing in regular text. Must be within CODE tags.

    John_G, thanks for sharing the solution. The cause seems so obvious now.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. SQL Statement Won;t Execute Programatically???
    By mrmmickle1 in forum Access
    Replies: 7
    Last Post: 12-08-2014, 08:35 PM
  2. Replies: 6
    Last Post: 05-16-2014, 07:26 AM
  3. puzzling syntax error in this query
    By BrockWade in forum Queries
    Replies: 16
    Last Post: 12-17-2013, 02:53 PM
  4. db.Execute Error 3061
    By JimG in forum Programming
    Replies: 5
    Last Post: 05-17-2010, 09:34 AM
  5. Puzzling #Name? error
    By sprovoyeur in forum Forms
    Replies: 9
    Last Post: 03-24-2010, 08:04 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