Results 1 to 3 of 3
  1. #1
    lena is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Oct 2014
    Posts
    3

    Need Help .."Data Type mismatch"

    strTableName Data :

    time (field)
    10/29/2014 12:05:52 AM
    10/28/2014 12:15:51 AM
    10/27/2014 7:52:48 PM
    10/26/2014 7:52:48 PM



    iwant to delete 27 and 26 data

    txtLastDate =10/29/2014 12:05:52 AM

    txtDate = Format(txtLastDate - 2, "yyyy-mm-dd hh:mm:ss")
    DoCmd.RunSQL "DELETE * FROM " & strTableName & " WHERE time < '" + txtDate + "'"

    error : Data Type mismatch in criteria expression.

    can anyone Help me .. how is the correct writing .

    any suggestions?

    Thanks

  2. #2
    amrut is offline Expert
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2012
    Location
    India
    Posts
    616
    If the field is of type date/time then the ' ( single quote) should be replaced with #.
    DoCmd.RunSQL "DELETE * FROM " & strTableName & " WHERE time < #" + txtDate + "#"

  3. #3
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    I also believe that you'll find that the + signs you've used for concatenation will bomb out in a SQL Statement! You need to replace the + signs with Ampersands, as you did in the first part of the statement, so that your final statement would be

    "DELETE * FROM " & strTableName & " WHERE time < #" & txtDate & "#"

    While the use of the + sign for concatenation is sometimes tolerated, in VBA code (for backwards compatibility, presumably) this isn't always true, and thus the practice should really be avoided, and the + sign reserved for doing math, in VBA code and SQL.

    Linq ;0)>

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

Similar Threads

  1. Unbound text box data type and "Delete" function
    By gaker10 in forum Programming
    Replies: 16
    Last Post: 06-13-2014, 10:46 AM
  2. Replies: 4
    Last Post: 01-11-2014, 11:57 PM
  3. Replies: 3
    Last Post: 05-31-2013, 04:32 PM
  4. How to format a "Number" Data type
    By undee69 in forum Access
    Replies: 4
    Last Post: 12-16-2012, 10:20 PM
  5. Replies: 2
    Last Post: 05-17-2011, 02:40 PM

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