dcsimg
Results 1 to 3 of 3
  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2018
    Posts
    52

    Resolved [RESOLVED] using a msg box to delete a record

    I would like to use a message box to run a delete query, here is what i have and it is not working at all,
    Code:
     MsgBox "record added with order number " + Combo970.Value
        
        'Me.Combo960 = Me.Combo970
        Answer = MsgBox("Do you wish to delete this record from Archive?", vbYesNo + vbExclamation + vbDefaultButton2, "Delete Confirmation")
    If Answer = vbYes Then
    DoCmd.SetWarnings False
        CurrentDb.Execute "DELETE * FROM Archive WHERE [Order Number] = Combo970.value", dbFailOnError
    DoCmd.SetWarnings True
    
    Else
    
    End If
    Exit_Combo970_AfterUpdate:
     Exit Sub
    
     
        ' So Now we have a new record in the table, its a matter of getting to it on the form
     
       'Me.Requery
        '  DoCmd.GoToRecord acLast
    End Sub

  2. #2
    Hyperactive Member
    Join Date
    Nov 2017
    Posts
    322

    Re: using a msg box to delete a record

    Presumably you should be doing something like this:

    Code:
    CurrentDb.Execute "DELETE * FROM Archive WHERE [Order Number] = " & Combo970.value, dbFailOnError

  3. #3
    PowerPoster
    Join Date
    Dec 2004
    Posts
    23,496

    Re: using a msg box to delete a record

    if the order number field in the DB is text, then you would need to enclose the value in ' '
    Code:
    CurrentDb.Execute "DELETE * FROM Archive WHERE [Order Number] = '" & Combo970.value & "'", dbFailOnError
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width