• Delete with a constant (Access 2000)

    Author
    Topic
    #415957

    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?

    Viewing 0 reply threads
    Author
    Replies
    • #928914

      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.

      • #928916

        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

    Viewing 0 reply threads
    Reply To: Delete with a constant (Access 2000)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: