Blank record inserted in table

  • Thread starter gmazza via AccessMonster.com
  • Start date
G

gmazza via AccessMonster.com

Hey there,
I have a main form and a subform. My subform's recordsource basically says
select * from table where id = id from my main form.
Works great but whenever I create a record in my main form it automatically
creates a blank record in the table that is the recordsource for my subform.
If I choose not to enter info in the subform for that id, I get a blank
record still in the table.
How can I prevent this?
Thanks!
 
D

Dirk Goldgar

gmazza via AccessMonster.com said:
Hey there,
I have a main form and a subform. My subform's recordsource basically says
select * from table where id = id from my main form.

Why aren't you just using the Link Master/Child Fields properties of the
subform control to handle the linkage?
Works great but whenever I create a record in my main form it
automatically
creates a blank record in the table that is the recordsource for my
subform.
If I choose not to enter info in the subform for that id, I get a blank
record still in the table.
How can I prevent this?

This is not normal behavior, so you must have code or a macro that is
assigning a value to one of the fields on the subform. Are you, for
example, assigning the ID field from the main form to the subform? If you
use the Link Master/Child Fields, you don't need such code. If that's not
the field you're assigning, I still think you must be assigning to *some*
field on the subform. What code or macros do you have that might do that?
 
G

gmazza via AccessMonster.com

To tell you the truth I didn't give all the details as I thought they
wouldn't matter but maybe they do.
I have a main form, a subform1 and another subform2.
My situation is happening on subform1 when I create a record, subform2's
recordsource is inserting a blank record.
I tried to link subform2 to subform1 but subform2 only gives me options to
link to the main form.
Should I put subform2 inside subform1 then?
Thanks for your answer.

Dirk said:
Hey there,
I have a main form and a subform. My subform's recordsource basically says
select * from table where id = id from my main form.

Why aren't you just using the Link Master/Child Fields properties of the
subform control to handle the linkage?
Works great but whenever I create a record in my main form it
automatically
[quoted text clipped - 3 lines]
record still in the table.
How can I prevent this?

This is not normal behavior, so you must have code or a macro that is
assigning a value to one of the fields on the subform. Are you, for
example, assigning the ID field from the main form to the subform? If you
use the Link Master/Child Fields, you don't need such code. If that's not
the field you're assigning, I still think you must be assigning to *some*
field on the subform. What code or macros do you have that might do that?
 
D

Dirk Goldgar

gmazza via AccessMonster.com said:
To tell you the truth I didn't give all the details as I thought they
wouldn't matter but maybe they do.

It's hard sometimes to know what details are relevant, but you should never
give details that you know are false, as you appear to have done.
I have a main form, a subform1 and another subform2.
My situation is happening on subform1 when I create a record, subform2's
recordsource is inserting a blank record.
I tried to link subform2 to subform1 but subform2 only gives me options to
link to the main form.
Should I put subform2 inside subform1 then?

You mean that you have both subforms on the main form, so subform2 is not
nested in subform1, but subform2 is dependent on subform1? While a somewhat
unusual arrangement, it's not unheard of, and the linking can be set up
through the Link Master/Child Fields of the subform control. However, you
need to create a "referring control" on the main form to act as the Link
Master Field for the subform. The referring control (which will probably be
hidden) would have a controlsource expression that picks up the value of the
linking field from subform1.

For example, you might have a hidden text box on the main form with these
properties:

Name: txtLink
Control Source: = [subform1].[Form]![ID]

Then subform2 (the subform control itself, on the main form) would have
these properties:

Link Child Fields: ID
Link Master Fields: txtLink

Have I understood correctly, and does that clarify what you need to do?
 
G

gmazza via AccessMonster.com

Thanks for your reply!
Your suggestion worked perfect, I thank you!

Dirk said:
To tell you the truth I didn't give all the details as I thought they
wouldn't matter but maybe they do.

It's hard sometimes to know what details are relevant, but you should never
give details that you know are false, as you appear to have done.
I have a main form, a subform1 and another subform2.
My situation is happening on subform1 when I create a record, subform2's
recordsource is inserting a blank record.
I tried to link subform2 to subform1 but subform2 only gives me options to
link to the main form.
Should I put subform2 inside subform1 then?

You mean that you have both subforms on the main form, so subform2 is not
nested in subform1, but subform2 is dependent on subform1? While a somewhat
unusual arrangement, it's not unheard of, and the linking can be set up
through the Link Master/Child Fields of the subform control. However, you
need to create a "referring control" on the main form to act as the Link
Master Field for the subform. The referring control (which will probably be
hidden) would have a controlsource expression that picks up the value of the
linking field from subform1.

For example, you might have a hidden text box on the main form with these
properties:

Name: txtLink
Control Source: = [subform1].[Form]![ID]

Then subform2 (the subform control itself, on the main form) would have
these properties:

Link Child Fields: ID
Link Master Fields: txtLink

Have I understood correctly, and does that clarify what you need to do?
 

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