Adding new records in Popup form

A

Alan B. Densky

I have an Access 2000 database.
I have a Parent table and a Child table.
The Parent table's key is LeadID - which is an autonumber field.
The Child table has a foreign key of LeadID - long Integer - Indexed but
more than one allowed
The tables are related in a 1 to many relationship
The Parent Table is the record source for the main form
I have a button on the main form to open another secondary form based on the
Child table, and limiting the records to the LeadID
When I open the secondary form from the main form, and add a record in the
secondary form, it is not filling in the LeadID automatically.

Duh! What am I missing here?

Alan
 
K

kingston via AccessMonster.com

When you say secondary form, I hope you mean subform (which means you don't
really mean open another secondary form). So, if this is a subform, check
the subform properties Link Child Fields and Link Master Fields. This will
automatically allow the main form to dictate the data relationship to the
subform.
 
A

Alan B. Densky

Hi,

No, it isn't a subform, it's actually another form that I am opening using a
button on the main form that is based on the Parent table.

I got it to work by adding code to the "BeforeInsert" of the secondary form
that I am opening. The code assigns the LeadID from the open main form, to
the LeadID field in the secondary form.

I know that there is an eaiser way to do this.

Alan
 
J

John Vinson

I have an Access 2000 database.
I have a Parent table and a Child table.
The Parent table's key is LeadID - which is an autonumber field.
The Child table has a foreign key of LeadID - long Integer - Indexed but
more than one allowed
The tables are related in a 1 to many relationship
The Parent Table is the record source for the main form
I have a button on the main form to open another secondary form based on the
Child table, and limiting the records to the LeadID
When I open the secondary form from the main form, and add a record in the
secondary form, it is not filling in the LeadID automatically.

Duh! What am I missing here?

If you're OPENING a separate form, it's completely independent of the
parent form; there is nothing automagical about the LeadID that will
cause it to be filled in.

The simplest solution is to make the second form a Subform of the
first, using the LeadID as the master and child link field. Then it
*will* automagically fill in. If you are pressed for screen real
estate, consider using a Tab Control - put the mainform's controls on
the first page, and the Subform on the second, for instance.

If you have some reason to want a separate, unrelated popup form,
you'll need to pass the LeadID in the OpenArgs argument of the
OpenForm method, and set the DefaultValue property of the LeadID
control in the second form's Open event. Doable, of course, but using
a subform requires no code at all.

John W. Vinson[MVP]
 
K

kingston via AccessMonster.com

I don't mean to be a smart ass, but the easier way to do it would be to use a
subform. Otherwise, you can use a query as the record source for the
secondary form where the query only returns records with the main form's
LeadID. You way works too. Don't fix it if it ain't broke.
Hi,

No, it isn't a subform, it's actually another form that I am opening using a
button on the main form that is based on the Parent table.

I got it to work by adding code to the "BeforeInsert" of the secondary form
that I am opening. The code assigns the LeadID from the open main form, to
the LeadID field in the secondary form.

I know that there is an eaiser way to do this.

Alan
When you say secondary form, I hope you mean subform (which means you don't
really mean open another secondary form). So, if this is a subform, check
[quoted text clipped - 17 lines]
 
A

Alan B. Densky

An easier way to do it would be a subform, yes, it would be, if I was
building this from scratch. But my main form is several years old, and I've
got a lot of code and controls on it, and there are a million other things
going on with it, and it's too much work to do that at this point.

I had tried filtering the secondary form in the SQL, but that wasn't
working. Either I'm getting senile, or there is something fishy going on in
my old database.

You are right, if it ain't broke, don't fix it. So I'm going to leave it the
way I've got it. But it bothers me when something doesn't work the way it's
supposed to, and there is no apparent reason why. But I guess that's Access
for you!

Thanks!

Alan


kingston via AccessMonster.com said:
I don't mean to be a smart ass, but the easier way to do it would be to use a
subform. Otherwise, you can use a query as the record source for the
secondary form where the query only returns records with the main form's
LeadID. You way works too. Don't fix it if it ain't broke.
Hi,

No, it isn't a subform, it's actually another form that I am opening using a
button on the main form that is based on the Parent table.

I got it to work by adding code to the "BeforeInsert" of the secondary form
that I am opening. The code assigns the LeadID from the open main form, to
the LeadID field in the secondary form.

I know that there is an eaiser way to do this.

Alan
When you say secondary form, I hope you mean subform (which means you don't
really mean open another secondary form). So, if this is a subform,
check
[quoted text clipped - 17 lines]
 
J

John Vinson

But it bothers me when something doesn't work the way it's
supposed to, and there is no apparent reason why.

Ummm... sorry, but it DOES work the way it's supposed to.

You're opening a new, independent, separate form, filtered to display
one record (or a specific set of records).

That's what you're asking Access to do. It's doing just that - opening
a new, independent form, displaying a particular record. There's
nothing in the WhereCondition or Filter operands of the OpenForm
method that affects what happens with NEW records on the form you're
opening, and it would break many applications if there were!

John W. Vinson[MVP]
 

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