Results 1 to 7 of 7
  1. #1
    msasan1367 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Feb 2013
    Posts
    60

    delete table record with VBA

    Hi


    This is my code:
    mypro is string
    prID is autonumber field
    Code:
    CurrentDb.Execute "delete from protbl where prID='" & mypro & "'"
    shows this error:
    Data type mismatch in criteria expression

  2. #2
    Symlink is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Mar 2013
    Posts
    42
    Wouldn't it be CurrentDb.Execute "DELETE * from protbl where prID='" & mypro & "'" ??

    Also to be sure you string is correct I would

    Dim test_string as String
    test_string = "
    DELETE * from protbl where prID='" & mypro & "'"
    MsgBox(test_string)

    Hope this helps.

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    For a numeric field:

    CurrentDb.Execute "delete * from protbl where prID=" & mypro
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    An AutoNumber field is a Long Integer (numeric) so your code should be:
    CurrentDb.Execute "Delete * from protbl where prID=" & mypro
    ...*not* enclosed in quotes.
    Edit: Darn, those lower altitudes let's Paul type faster.

  5. #5
    Symlink is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Mar 2013
    Posts
    42
    Oops apparently didn't take enough time to read the numeric field part. Sorry

  6. #6
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    It is a real good thing that Paul and I have never made that mistake!

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Quote Originally Posted by RuralGuy View Post
    Edit: Darn, those lower altitudes let's Paul type faster.
    Whaddaya mean? The thicker air down here means my fingers have to work harder to push through it!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 4
    Last Post: 07-03-2013, 10:02 AM
  2. Replies: 3
    Last Post: 10-19-2012, 04:30 PM
  3. Replies: 2
    Last Post: 01-24-2012, 02:16 PM
  4. Trying to Delete record using delete query
    By MooseOTL in forum Access
    Replies: 13
    Last Post: 10-04-2011, 02:30 AM
  5. Replies: 12
    Last Post: 09-09-2011, 11: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