This topic is locked

Hide Add Button or enforce 1 to 1

7/22/2010 5:56:35 AM
ASPRunnerPro General questions
Stu author

I have an sql table where I want to enforce 1 to 1 relationship with a Master Record so that you can ADD one child record - but that's it. I guess I can check to see if a record exists and if it does I want to disable/hide the ADD button but I will allow an Edit.
What code do I need to add and where pls.

A
ann 7/22/2010

Hi,
use Before process event on the Events tab for child table.

Here is a sample:

dim rsExists

if Session(strTableName & "_masterkey1")<>"" then

set rsExists = CustomQuery("select count(*) from DetailTable where DetailTableLinkField='" & Session(strTableName & "_masterkey1") & "'","")

if rsExist(0)>1 then

response.redirect "tablename_list.asp?a=return"

end if

rsExists.Close : set rsExists = Nothing

end if



where DetailTable is your actual master table name, DetailTableLinkField is actual link field name.