Results 1 to 3 of 3
  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Posts
    254
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Delete with a constant (Access 2000)

    I want to delete a record from the table depending on the constant.
    For example,if i want to delete the following numbers:
    5,28,40,69
    Then i put them in brackets as " In ( 5,28,40,69) and then execute a delete query.

    This i have done with the following code:
    Public Const STrIn = " In (5,28,40,69)"
    Dim Bas As String
    Bas = " delete * from tblClients where Clientid " & STrCl & ""
    CurrentDb.Execute Bas

    To my regret the code deletes all the records from the table and not just those in the constant.
    How can i delete only the selected records ?
    And also, what shall i do if a number from the constant is not existing?

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 28 Times in 28 Posts

    Re: Delete with a constant (Access 2000)

    It helps to be consistent. You define a constant named STrIn but you use STrCl in the SQL string. Apparently, you don't have Option Explicit in your module, otherwise you'd have gotten a syntax error. Changing STrCl to STrIn should make the code work.

    It doesn't matter if one of the ClientIDs in the In (...) list does not exist in the table. This will not cause an error message.

  3. #3
    3 Star Lounger
    Join Date
    Jan 2001
    Posts
    254
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Delete with a constant (Access 2000)

    Thank you very much. And also thank you for your patience,sometimes i ask stupid questions.I just thought the code will never work
    wand was in despair.
    So thank you once again

Posting Permissions

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