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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cannot add a record from a form 1

Status
Not open for further replies.
Jul 24, 2000
88
CA
Now here's a strange question... I added a record into a child table using a form opened from the parent form. While trying to solve another problem, I think I must have changed something because I can not add child records any more! I get the error message "Cannot add or change a record because a related record is required in the Projcts table.

The related record does exist in the parent Projects table so I'm not sure why it cannot be found!

My Query behind the child form just contains the child table - the parent table is not included.

I have a relationship set up joining the parent to the child.

Do I need to add the parent table into the Query behind the child form? If I do, do I need to select the foreign key that points to the parent?

Any help would be great.

Thanks,
Richard
 
Hallo,

Sounds like the link between your form and subform might be broken.
Other than that we need more to go on. Can you give us a better description of your forms/tables and the recordsources/relationships/linking between them

- Frink
 
Hi Frink, thanks for helping me out here.

I have a relationship defined between a Projects parent table joined to the ProjectAnnouncements child table with a one-to-many join.

The parent form - Form_frmProjects has a RecordSource of qryProjects. This query has the Projects parent table joined to the ProjectAnnouncements child table with a one-to-many join - like the relationship described above. I have this joined query so that I can list all announcements for a Project on frmProjects. I call the frmProjectAnnouncements using 'DoCmd.OpenForm "frmProjectAnnouncements", , , strLinkCriteria'. The strLinkCriteria is set to "Project_ID_long = " followed by the selected Project_ID. This looks correct as I single-step through the code.

The child form - Form_frmProjectAnnouncements has a RecordSource of qryProjectAnnouncements. This query is a simple view of the ProjectAnnouncements child table.

Hope this info explains my situation.

Thanks for any help you can give...
RjB
 
Why not using a SubForm with defined LinkChildFields and LinkMasterFields properties ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Thanks for your SubForm idea PH but I have too much info to include on a form & subForm unless there's a way to move the subform in relation to the master form or hide it behind the master form.

By the way, When I created the form-subform, I could add records to the child table through the subform - the thing I was having dofficulty with with the called form. I would appreciate any other suggestions you may have. In the meantime, I'll try to compare the properties etc of the form-subform setup with my called form setup and see if I can determine why I cannot add records.

Thanks again.
RjB
 
Hallo,

If you open the child form with the Project_ID_long = Project Id then it will only display the requred records for that project.
When you add a record the value used for ProjectId will be whatever is set up in the table as the default value, which almost certainly wan't be what you want.
Try sending the project Id in the OpenArgs on opening of the form. You should then be able to put:
me!ProjectId=Me.OpenArgs
in the BeforeInsert (I think) event.

- Frink
 
Hi Frink. I figured out the solution while brushing my teeth last night and it was as you said, I need to set up the Project_ID_long each time I insert a new ProjectAnnouncements record. Three gold stars for you!!!

One thing I have been wondering about - what is the difference between Me. and Me! I see both used in various places but can't remeber what the differences are.

Another thing - is there any reference around anywhere that lists and defines the standard Access Object such as OpenArgs, all the record manuipulation objects and the hundreds of others? I get so frustrated not knowing what objects and methods to use and what the argument and return structure is.

Thanks again for your help.

RjB
 
When in VBE press the F2 key to open the Object browser and then feel free to play with the F1 key.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Hallo,

Me is the form the code is currenntly running in.

Use Me. for propetries and methods of the form.
ie. Me.Name, Me.Recordsource

Me! is actually shorthand for Me.Controls! and you use it to refer to controls on your form.
ie. Me!txtTotal, Me!fraSize

Not sure about refering to fields in the underlying recordset of a form. You can do Me!lngPersonId to get the value of a field, even if it's not represented in a Control.

The above also works for Reports.

If you look up Collections and Objects in help, and use the See Also links to navigate around that should be more than enough to be getting on with :)

- Frink
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top