Check for existing Records on Delete

  • Thread starter Thread starter Lance
  • Start date Start date
L

Lance

Hello,

I have two tables, tblOrg, and tblPrograms. I have a form frmOrg, which
has all of the Organization data. I also have a Delete button, so you
can delete an organization from the database. I would like to create a
check to see if the OrgID from tblOrg exists in tblPrograms first,
however, so that I can give my users an error message saying they can't
delete an Organization that has existing data elsewhere. What is the
best way to go about this?

Thanks,

Lance
 
Assuming the field containing the OrgID in tblPrograms is called OrgID and
there is a control on the form called OrgID which holds this Organizations
ID (Me.OrgID):

If IsNull(DLookup("OrgID", "tblPrograms", "[OrgID] = 'me.OrgID'")) Then
docmd.runsql "delete whatever from wherever"
Else
MsgBox "You can't delete an Organization while data exists!"
End If
 
You could also create some RI between the tables but without the cascade
delete option. Access will then prevent you from deleting the parent row if a
child exists
--
HTH

Chris


SusanV said:
Assuming the field containing the OrgID in tblPrograms is called OrgID and
there is a control on the form called OrgID which holds this Organizations
ID (Me.OrgID):

If IsNull(DLookup("OrgID", "tblPrograms", "[OrgID] = 'me.OrgID'")) Then
docmd.runsql "delete whatever from wherever"
Else
MsgBox "You can't delete an Organization while data exists!"
End If

--
hth,
SusanV


Lance said:
Hello,

I have two tables, tblOrg, and tblPrograms. I have a form frmOrg, which
has all of the Organization data. I also have a Delete button, so you
can delete an organization from the database. I would like to create a
check to see if the OrgID from tblOrg exists in tblPrograms first,
however, so that I can give my users an error message saying they can't
delete an Organization that has existing data elsewhere. What is the
best way to go about this?

Thanks,

Lance
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top