Inserting new record problem

J

Jorge Ribeiro

Hello

I've three tables: Document, Contact and DocumentContact.
On the first one rest document info like subject, date, and so on.
On the second there are several info related to Contact (name, address, etc)
The third one is a relation table that has two columns: DocumentId and
ContactId.
So i can associat on document to several contacts and vice-versa

I made a form for insert/update a Document record.
In that form i have a listbox with several contacts to choose from and
populate the
table DocumentContact.
This works fine for already inserted documents but fails for new ones.

In my Add button, that adds a contact to the list of assoociated contacts,
vba code
creates a new record in DocumentContact table and sets ContactId and
DocumetnId accordingly.
The problem arises when trying to update that recordset... it seems that
because i'm in a new document record it dows not let me associate any record
with that new one.

hope you can undestand me

Can you help me here?

Regards

Jorge
 
J

Jim Burke in Novi

Are you saying you're adding both a new document and a new contact, so you
need to add new entries for both of those as well as the new DocumentContact
entry? Or you're just adding a new document, and selecting a ContactID, and
then trying to add the new DocumentContact record for that combination? I
guess regardless, before you can add a record to DocumentContact, the IDs for
Document and Contact must already be saved in the database. My guess is that
you may have created a new document or contact record, but haven't actually
saved it yet. Until you save it you don't know what the new ID is.
 
T

tina

try adding code to the Add command button, *before* the code that adds the
new record to the DocumentContact table, as

If Me.Dirty Then Me.Dirty = False

that code saves the current record.

hth
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top