Results 1 to 5 of 5
  1. #1
    Join Date
    Nov 2002
    Location
    Oakland, CA
    Posts
    126

    Unanswered: What's wrong with my code?

    What's wrong with this code? Every time I click on the button, the statement .execute gets highlighted.... I'm trying to delete a record based on selection from a list:

    Private Sub butDeleteProduct_Click()
    Dim MyDB As Database
    Dim MySet As Recordset

    Set MyDB = CurrentDb
    MySet = MyDB.Execute("DELETE SpecialDetailKey FROM tblSpecialDetail WHERE (((tblSpecialDetail.SpecialDetailKey)=[Me]![lstDetail]));")
    MySet.Close

    End Sub

  2. #2
    Join Date
    Sep 2003
    Posts
    228
    MySet = MyDB.Execute("DELETE SpecialDetailKey FROM tblSpecialDetail WHERE tblSpecialDetail.SpecialDetailKey=" & [Me]![lstDetail])

    You had your variable inside the quotations. If you want the variable to be subtituted for the actual value then it has to be outside of the quotes.

  3. #3
    Join Date
    Nov 2002
    Location
    Oakland, CA
    Posts
    126
    did as suggested, however, the .execute still gets highlighted...

  4. #4
    Join Date
    Nov 2003
    Location
    Sussex, England
    Posts
    404
    did as suggested, however, the .execute still gets highlighted...
    As it should - you don't execute recordsets you open them. Try declaring mySet as a string variable and try again.

  5. #5
    Join Date
    Sep 2003
    Posts
    228
    Quote Originally Posted by ottomatic
    MySet = MyDB.Execute("DELETE SpecialDetailKey FROM tblSpecialDetail WHERE tblSpecialDetail.SpecialDetailKey=" & [Me]![lstDetail])

    You had your variable inside the quotations. If you want the variable to be subtituted for the actual value then it has to be outside of the quotes.
    try this:
    dim SQLStr as string

    SQLStr = "DELETE SpecialDetailKey FROM tblSpecialDetail WHERE tblSpecialDetail.SpecialDetailKey=" & [Me]![lstDetail]

    docmd.runsql(SQLStr)

Posting Permissions

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