Delete issue

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • compwizard
    New Member
    • Feb 2008
    • 12

    Delete issue

    hello all,

    Just a quick query

    I currently have an hires form where clients place orders,
    When an item is selected this would drop the item within a listbox and save within a itemhireline table. If clear is selected half way through an order i want the items within the listbox to be deleted from the tblitemhireline so when the next order is placed the listbox should be empty. It sounds pretty simple but i cannot get it to delete all the items that are linked to this itemhireno.

    This is what i have been using - it only deletes one item every time the form is cleared

    Set rstclear = database.OpenRe cordset("Select * from itemhireline Where itemhirno=" & Forms!frmitemhi reform!txtitemh ireno)
    rstclear.Delete
  • Megalog
    Recognized Expert Contributor
    • Sep 2007
    • 378

    #2
    Originally posted by compwizard
    Set rstclear = database.OpenRe cordset("Select * from itemhireline
    Where itemhirno=" & Forms!frmitemhi reform!txtitemh ireno)
    rstclear.Delete
    Try something like this... There's probably a better way to handle the looping than using a goto.. <shrug> Back up your data first!

    Code:
    Dim rstclear as DAO.Recordset
    Dim itm as Variant
    
    Set rstclear = CurrentDb.OpenRecordset("itemhireline", dbOpenDynaset)
    Repeat:
    rst.FindFirst "itemhirno = " & [Forms]![frmitemhireform].[txtitemhireno]
    if rst.nomatch = False Then
         rstclear.Delete
         goto Repeat
    end if
    Set rstclear = nothing

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32634

      #3
      Code:
      Do [criteria]
      ...
      Loop [criteria]
      Code:
      While [criteria]
      ...
      Wend
      Code:
      For Var = X To Y [Step Z]
      ...
      Next Var

      Comment

      Working...