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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Discontiniue delete-On Delete Event ...Before Delete Confirmation

Status
Not open for further replies.

Zirak

MIS
Feb 3, 2003
164
US

Hi,
Before I delete a record on from a form, I want to check and see if that ID exists in another table, If so I want to discouninue the delete procedure, here is my code:
(I'm using a SQL server backend)

Dim CSet As ADODB.Recordset
Dim strSQL

strSQL = "Exec dbo.SP_FindCompanyOnDelete " & Me!CompanyID

Set CSet = New ADODB.Recordset
CSet.ActiveConnection = CurrentProject.Connection
CSet.Open strSQL
If CSet.EOF Then
CSet.Close
Exit Sub
Else
CSet.Close
MsgBox "There are Contacts assigned to this company." _
& Chr(13) & "Delete the company from those contacts first and then delete the Company.", vbCritical, "Delete Responses First"
End If



 
And ?
I don't understand your problem ... [bat]
If you look for the good event, you should put your code into the BeforeDelConfirm event


Private Sub Form_BeforeDelConfirm(Cancel As Integer, Response As Integer)

Dim CSet As ADODB.Recordset
Dim strSQL

strSQL = "Exec dbo.SP_FindCompanyOnDelete " & Me!CompanyID

Set CSet = New ADODB.Recordset
CSet.ActiveConnection = CurrentProject.Connection
CSet.Open strSQL

If not(CSet.EOF) Then
MsgBox "There are Contacts assigned to this company." _
& Chr(13) & "Delete the company from those contacts first and then delete the Company.", vbCritical, "Delete Responses First"
cancel = true 'to cancel deleting
End If

CSet.Close
set Cset = nothing

End Sub


Hope that helps

SEB
 
I got it.
i used the cancel event

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top