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!

Linked Forms/Add Record

Status
Not open for further replies.

sweevo

Programmer
Jan 30, 2002
182
GB
I am inexperienced with Access programming and am having trouble with linked forms.

There are two tables as follows:

Contacts
--------
Contact ID (Replication ID)
Surname
Forename
etc

Notes
-----
Note ID
Contact ID
Note Date
Note Header
Note Text
Created By

The user selects a Contact, and clicks a "Notes" button. This shows a form for that Contact, and shows the notes attached to them in a summarised datasheet sub-form (this shows Contact ID, Note ID, Note Date and Note Header).

There is an Edit button, which opens another form showing the full details of the Note selected on the datasheet. The detail form is simply opened with the criteria of Note ID, so the correct record shows for editing.

I want an Add New button, that opens up the same (or similar) form as the detail one that opens for editing, but I need the new form to be linked to the Contact ID of the Contact currently open. At the moment I can only get a completely blank note record to open (blank Contact ID also), it is not intrinsically linked to the relevant Contact.

I've tried opening the form with Contact ID criteria, passing the Contact ID as an OpenArg etc but they don't work.

I hope my problem is clearly explained, any help would be appreciated.

Thanks
 
Hallo,

You're on the right lines. What you have to do is pass the ContactId to the new form and add it in before the record is saved.

In the Add New button OnClick you should have an OpenForm statement. The last parameter of this is called OpenArgs. Set this to the Contact Id. I forget how many parameters there are but it should look something like
Docmd.openform "frmNewNotePopup",,,,,,,,,,,,,,,Me!ContactId

In the popup forms BeforeUpdate for the record, put Me!ContactId=Me.OpenArgs. This assumes that frmNewNotePopup is based on the Notes table.
This will copy the contact Id from the OpenArgs into the underlying table immediately before the record is saved.

That should do it.


- Frink
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top