VBA button code/table

pauld118

Registered User.
Local time
Today, 13:48
Joined
Jun 17, 2011
Messages
21
Hello everybody,

I have a MasterTable that have many "One to Many" relationships with other tables. These relationships are made by a foreing key, which is an ID that is shown in the MasterTable. The others tables have Text, Date, Number and Yes/No data type.

I am creating a form that will populate the master table. The master table records name of facilities. One of the other tables is named Inspections, meaing that each facility may have several inspections. I created the boxes that will populate the Inspection Table in the Form. Have in mind that what will be save on the mastertable is the ID of the Inspection.

I would like to create a button in the form that will add a new record in the inspection table while adding a new InspectionID in the master table. So far, codes that I've found don't work. Any ideas???:confused::confused::confused:

Thanks!
 
You're going about this backwards. The Foreign Key goes in the "many" side (child) table. So in your "master table" (the parent table - which has something to do with facilities) you should have a Primary key like FacilityID. You then put a FacilityID field in the child tables as a Foreign Key.

Then, you set up a main form based on the "master" table, or a query thereof, with a sub form based on the child table. If done correctly, the Master/Child link property of the sub form control will automatically enter the appropriate Foreign Key value when you add new records to the sub form.
 
Thank you very much Beetle!

Is there a way of doing that without using a subform??? Like creating the button that will show hidden fields or even a input box to enter the data for the new record for the inspection table???
 

Users who are viewing this thread

Back
Top Bottom