Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

deleting record on form from button on subform

Status
Not open for further replies.

Earth

Technical User
May 8, 2000
59
0
0
AU
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
 
HI,
Try with this code after the exist code in the DELETE button in the versions subform.

dim sSQL as string
dim rsAux as recordset

sSQL = "SELECT * FROM Table_Versions WHERE IdVersion = " & Me.ControlNameOf_IdVersion
set rsAux = codedb.openrecordset(sSQL)
IF (rsaux.EOF and rsAux.BOF) THEN
' You need delete Document record
sSQL = "DELETE * FROM Table_Document WHERE IdDocument = " & Me.ControlNameOf_IdDocument
codedb.Execute SSQL
ENDIF
Me.Requery
Me.[Versions Subform].Requery

Bye, Vero.
vzudaire@yahoo.com My e-mail is: vzudaire@yahoo.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top