Results 1 to 3 of 3
  1. #1

    Thread Starter
    Join Date
    Feb 2018

    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,
     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
    End If
     Exit Sub
        ' So Now we have a new record in the table, its a matter of getting to it on the form
        '  DoCmd.GoToRecord acLast
    End Sub

  2. #2
    Hyperactive Member
    Join Date
    Nov 2017

    Re: using a msg box to delete a record

    Presumably you should be doing something like this:

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

  3. #3
    Join Date
    Dec 2004

    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 ' '
    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

Posting Permissions

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


Click Here to Expand Forum to Full Width