Results 1 to 7 of 7
  1. #1
    angie is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Dec 2013
    Posts
    232

    Delete command to update record


    Hi I have a form (service calls)where calls are entered once the calls are completed I go to the record and click on invoice button that opens the invoice form and I create a invoice (they are linked by service call Id) I would like to create a code that would delete the "service calls " form once the invoice is created.

    Form were call is created "service calls"
    form were invoice is created "invoice"
    link by "service call id"

    Thank you Angie

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Are you asking how to delete a record? You mention a form in your post. Instead of deleting a record that is associated with an invoice, why not update the record as being invoiced? I would create a Boolean field/column in the original table to indicate the invoice status or just rely on the ID relationship between the two tables. I would not delete any records. Deleting related records goes against convention.

  3. #3
    angie is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Dec 2013
    Posts
    232
    I have a form that is just used for calls that has date time and who will do call, once it is completed I create a invoice in detail so I just need to delete the call I have no need to keep it once it is invoiced. I have a customer record that is never deleted.

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Here is some code that you can place in a click event. You will need to adjust the text in red to match the form's control name, table name, and field name. This will delete a single record in the table that is associated with the ID field currently displayed in the form

    Code:
    Dim rs As DAO.Recordset
    Set rs = CurrentDb.OpenRecordset("tblName", dbOpenDynaset)
        If rs.EOF Then
            rs.Close
            Set rs = Nothing
        Exit Sub
        End If
    rs.FindFirst "[IDFieldName] = " & Me.IDControlName.Value
        If rs.NoMatch Then
            MsgBox "Could Not Find Record to delete."
            rs.Close
            Set rs = Nothing
        Exit Sub
        End If
    rs.Delete
        MsgBox "The record has been deleted."
    rs.Close
    Set rs = Nothing

  5. #5
    angie is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Dec 2013
    Posts
    232
    That works great. I add to Requrey the attached form also. Do I have to leave the pop up that record has been deleted. Thanks again Angie

  6. #6
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    it is perfectly OK to remove the following

    MsgBox "The record has been deleted."

    or any MsgBox code for that matter.

  7. #7
    angie is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Dec 2013
    Posts
    232
    Thank you very much. Have a Merry Christmas.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 06-21-2013, 10:41 AM
  2. Replies: 3
    Last Post: 10-19-2012, 04:30 PM
  3. Replies: 12
    Last Post: 03-14-2012, 10:54 AM
  4. Error handling for delete record command
    By jobrien4 in forum Access
    Replies: 2
    Last Post: 09-16-2011, 11:00 AM
  5. Command button help - delete record
    By Zukster in forum Forms
    Replies: 0
    Last Post: 08-27-2009, 08:47 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums