Results 1 to 6 of 6
  1. #1
    4 Star Lounger
    Join Date
    Oct 2002
    Location
    Sayre, Pennsylvania, USA
    Posts
    504
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Need Help with Code (2000)

    Hi,
    I have the following code and I'd like to add to it.
    Private Sub cmdRemovePartRichExist_Click()
    Me.ysnPartOrdered = False
    Me.Requery
    End Sub
    This code works well. What I like to add is when the button is clicked it also deletes that particular part out of the tblOrderDetails table. The lngPartsID is how the part is identified.
    I'm not sure how to go about this code.
    Thanks,
    Deb

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

    Re: Need Help with Code (2000)

    You could add

    Dim strSQL As String
    strSQL = "DELETE * FROM tblOrderDetails WHERE lngPartsID = " & lngPartsID
    DoCmd.RunSQL strSQL

    Just as when you run an action query, you'll be warned that you are about to delete n records. This is useful during development, it'll give you feedback as to what the code is actually doing, but you don't want the end user to see those warnings. You can suppress them as follows:

    ...
    DoCmd.SetWarnings False
    DoCmd.RunSQL strSQL
    DoCmd.SetWarnings True

  3. #3
    4 Star Lounger
    Join Date
    Oct 2002
    Location
    Sayre, Pennsylvania, USA
    Posts
    504
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Need Help with Code (2000)

    Hi Hans,
    Thanks for your reply. I have the code below but it's not quite working. When I click the button the flag part works, I get the delete 1 record message, I say yes, but it seems to be deleting the record below the one I want. I have the button next to each record on a subform that is in continuous form. When they click the remove part button, that's the part I want to be deleted from the tblOrderDetails table.

    Private Sub cmdRemovePartRichExist_Click()
    Me.ysnPartOrdered = False
    Me.Requery

    Dim strSQL As String
    ' DoCmd.SetWarnings False
    strSQL = "DELETE * FROM tblPROrderDetails WHERE lngPartsID = " & lngPartsID
    DoCmd.RunSQL strSQL
    ' DoCmd.SetWarnings True
    End Sub
    Thanks,
    Deb

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

    Re: Need Help with Code (2000)

    What happens if you put the line Me.Requery below the part that deletes a record?

  5. #5
    4 Star Lounger
    Join Date
    Oct 2002
    Location
    Sayre, Pennsylvania, USA
    Posts
    504
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Need Help with Code (2000)

    Thanks Hans,
    That did the trick. I'm not sure if they want to remove the price yet or not, but just in case if they wanted to remove the price out of the curUnitPrice field how would I do that.
    Thanks,
    Deb

  6. #6
    4 Star Lounger
    Join Date
    Oct 2002
    Location
    Sayre, Pennsylvania, USA
    Posts
    504
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Need Help with Code (2000)

    Never mind that last question I used: Me.curUnitPrice = null and it seems to be working the way i want.
    Thanks,
    Deb

Posting Permissions

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