Hi,
I have a form (Documents) and a subform (Versions).
There is a delete button on the form which works pefectly: deletes the currect document record, and (cascade) deletes versions linked to it.
There is a delete button on the versions subform which deletes the correct version record. However, I wish to make a check so that once all versions of a document are deleted, the document record is also deleted. I have the code behind this button set up with the relevant checks, my problem is when it actually comes to deleting the document (from the versions subform![delete button] code.
The code that I use to remove documents (in my documents form) is....
Private Sub Delete_Click()
Dim Last As Integer
' Confirm the deletion
If MsgBox("Are you sure you wish to delete this document?", 305) = 1 Then
' See if on the last record (if the last record is deleted, the form moves off the end of the table
Me.RecordsetClone.MoveLast
Last = Me.RecordsetClone.Fields("DRegistrationNumber"
= Me![DRegText]
' Delete the record
DoCmd.SetWarnings False
RunCommand acCmdDeleteRecord
DoCmd.SetWarnings True
' Move to the new last record
If Last Then
DoCmd.GoToRecord , , A_LAST
End If
Me![Versions subform].Requery
End If
End Sub
My question is... how do i adapt that to work off my subform? or is there a better way???
I know I don't need
Me![Versions subform].Requery =)
And
Forms![Documents].RecordsetClone.MoveLast
Last = Forms![Documents].RecordsetClone.Fields("DRegistrationNumber"
= Forms![Documents]![DRegText]
seems to work, but.....help?
thanks in advance
I have a form (Documents) and a subform (Versions).
There is a delete button on the form which works pefectly: deletes the currect document record, and (cascade) deletes versions linked to it.
There is a delete button on the versions subform which deletes the correct version record. However, I wish to make a check so that once all versions of a document are deleted, the document record is also deleted. I have the code behind this button set up with the relevant checks, my problem is when it actually comes to deleting the document (from the versions subform![delete button] code.
The code that I use to remove documents (in my documents form) is....
Private Sub Delete_Click()
Dim Last As Integer
' Confirm the deletion
If MsgBox("Are you sure you wish to delete this document?", 305) = 1 Then
' See if on the last record (if the last record is deleted, the form moves off the end of the table
Me.RecordsetClone.MoveLast
Last = Me.RecordsetClone.Fields("DRegistrationNumber"
' Delete the record
DoCmd.SetWarnings False
RunCommand acCmdDeleteRecord
DoCmd.SetWarnings True
' Move to the new last record
If Last Then
DoCmd.GoToRecord , , A_LAST
End If
Me![Versions subform].Requery
End If
End Sub
My question is... how do i adapt that to work off my subform? or is there a better way???
I know I don't need
Me![Versions subform].Requery =)
And
Forms![Documents].RecordsetClone.MoveLast
Last = Forms![Documents].RecordsetClone.Fields("DRegistrationNumber"
seems to work, but.....help?
thanks in advance