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!

Populate a table but check for existing entries

Status
Not open for further replies.

Lockstock2SB

Technical User
Oct 29, 2001
53
GB
Hi There

I have a main form that displays customers details (FRMClient). On this form i want a button that loads a new form.

This new form i need to be linked to a brand new table/query as it will house quite a few 5 digit numbers and various other company-specific details. Basically this new form needs to display chequebook requests and hold previous cheque book numbers etc..all unique data.

But when i have selected the customer on FRMClient and click the button i want to pull up the record that already exists in the table (if it does exist) and display that in the form, or if it does not exist i want to add the values to the table automatically and then display the form. I dont not want any duplicate companies in the table.

I have managed to add new records to the table by establishing a recordset and adding them but if i repeatedly click the button to open the form all it does is add more and more entries for the same company which is no good as i want 1 record for each company that has all the info unique info attached and be able to keep going back and adding to it. I would go back to the record by selecting the customer on FRMClient again and hitting the button and it would find the record and disply it in the new form...

Any ideas !? I bet its quite simple for most of you by my head is spinning as i am not an expert ! :)

Cheers

Steve
 
If I understand correctly this is a One to One relationship.

For this you have to have a Primary key on the first table and a foreign key on the second table

Before Add the records to the table add this IF Statment

If not isnull(Dlookup(Foreign key,second Tablename," Foreign key=Primary key")) then

add record

end if


 
Thanks for the reply mate ! :)

I will try that and post back my findings shortly !

Cheers

Steve
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top