Deleting Record Problem

Ally

Registered User.
Local time
Today, 20:02
Joined
Sep 18, 2001
Messages
617
I have a form with a delete button, with the code the wizard put behind, but added code to ask for confirmation and select another form and requery it once deleted.

I've used the same code before on a number of occasions, but on this particular form, when I say yes, it deletes the information in the record, but sets the primary key to 0, so in fact there is still a record there.

Does anyone know why this is please?
 
Code:
Private Sub cmdDelete_Click()
On Error GoTo Err_cmdDelete_Click
   Dim UserResponse As Integer
   
   DoCmd.SetWarnings False

   UserResponse = msgbox("Are you sure you wish to delete _ 
       the current record?", vbYesNo, "Delete?")
   
   If UserResponse = vbYes Then
      DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
      DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
      DoCmd.Close
      DoCmd.SelectObject acForm, "frmPatient"
      DoCmd.Restore
      Forms![frmPatient]![lstEpisode].Requery
    
   End If

    DoCmd.SetWarnings True

Exit_cmdDelete_Click:
    Exit Sub

Err_cmdDelete_Click:
    msgbox Err.Description
    Resume Exit_cmdDelete_Click
    
End Sub
 
Code:
Private Sub cmdDelete_Click()
On Error GoTo Err_cmdDelete_Click
   

If msgbox("Are you sure you wish to delete _ 
the current record?", vbYesNo, "Delete?") = vbyes then
   
      DoCmd.SetWarnings False
      DoCmd.runcommand accmddeleterecord            
      DoCmd.Close
      DoCmd.SelectObject acForm, "frmPatient"
      DoCmd.Restore
      Forms![frmPatient]![lstEpisode].Requery
      DoCmd.SetWarnings True
End If


Exit_cmdDelete_Click:
    Exit Sub

Err_cmdDelete_Click:
    msgbox Err.Description
    Resume Exit_cmdDelete_Click
    
End Sub

If this code on the frmPatient I'm not quite sure why you are doing this though rather than me.refresh / requery.

Code:
 DoCmd.Close
 DoCmd.SelectObject acForm, "frmPatient"
 DoCmd.Restore

any help?
 
Oh that's excellent, works a treat - thanks Fizz.

(The information is on another form - but the frmPatient displays the information that's just been deleted in a listbox, which is why it's being requeried).
 

Users who are viewing this thread

Back
Top Bottom