Prevent data from adding if data is not in the table

Guys, need help with the coding and where to write it. I’m using lookup table and auto fill.

I have 2 table…

Table 1
id
item_code
item_name

Table 2
id
item_code
item_name
vendor_code
vendor_name

Im using lookup table from Table1 for the item_code field in Table 2… It will automatically fill the item_name in Table 2 if it find the same value in table 1. Currently, if there is no value for the item_code in Table1, my page will still allow me to add with the new data. I want to prevent it from adding or at least if the lookup table fail to find the same code_name in Table 1, it will prevent the user from adding or at least there’s a warning message for the user. Any suggestion? Need help with the coding though…

For form validation, use Form_CustomValidate server event and client script. Please refer to the example in the help file - Server Events and Client Scripts.