Add 2 rows at 1st time

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi!

I have an AppendQuery that add two rows when us it at 1st time.
Why, please?

Thanks in advance.
an
 
INSERT INTO T_PCont ( IdLocal, [Local], IdOcorr, Ocorr, NameOcorr, IdProc,
Proc, NProc )
SELECT T_Locals.IdLocal, T_Locals.Local, T_Ocorr.IdOcorr, T_Ocorr.Ocorr,
T_Ocorr.NameOcorr, T_Proc.IdProc, T_Proc.Proc, T_NProc.NProc
FROM T_Proc, T_Ocorr, T_NProc, T_Locals
WHERE (((T_Locals.IdLocal)=[Forms].[F_PCont].[txtIdLocal]) AND
((T_Locals.Local)=[Forms].[F_PCont].[txtLocal]) AND
((T_Ocorr.IdOcorr)=[Forms].[F_PCont].[txtIdOcorr]) AND
((T_Ocorr.Ocorr)=[Forms].[F_PCont].[txtOcorr]) AND
((T_Ocorr.NameOcorr)=[Forms].[F_PCont].[txtNameOcorr]) AND
((T_Proc.IdProc)=[Forms].[F_PCont].[txtIdProc]) AND
((T_Proc.Proc)=[Forms].[F_PCont].[txtProc]) AND
((T_NProc.NProc)=[Forms].[F_PCont].[cboNProc]));

Thank you.
an
 
Hi!

I have an AppendQuery that add two rows when us it at 1st time.
Why, please?

Because there's an error in the query.

My guess is that the query joins two tables, and (for this record) there are
two records in the joined table.

Please post the SQL.

John W. Vinson [MVP]
 
INSERT INTO T_PCont ( IdLocal, [Local], IdOcorr, Ocorr, NameOcorr, IdProc,
Proc, NProc )
SELECT T_Locals.IdLocal, T_Locals.Local, T_Ocorr.IdOcorr, T_Ocorr.Ocorr,
T_Ocorr.NameOcorr, T_Proc.IdProc, T_Proc.Proc, T_NProc.NProc
FROM T_Proc, T_Ocorr, T_NProc, T_Locals
WHERE (((T_Locals.IdLocal)=[Forms].[F_PCont].[txtIdLocal]) AND
((T_Locals.Local)=[Forms].[F_PCont].[txtLocal]) AND
((T_Ocorr.IdOcorr)=[Forms].[F_PCont].[txtIdOcorr]) AND
((T_Ocorr.Ocorr)=[Forms].[F_PCont].[txtOcorr]) AND
((T_Ocorr.NameOcorr)=[Forms].[F_PCont].[txtNameOcorr]) AND
((T_Proc.IdProc)=[Forms].[F_PCont].[txtIdProc]) AND
((T_Proc.Proc)=[Forms].[F_PCont].[txtProc]) AND
((T_NProc.NProc)=[Forms].[F_PCont].[cboNProc]));

You're joining *four* tables without ANY join clause or criteria. If any one
of these tables has two records in it you'll see two records in the result; if
two tables each have two records you'll see all four possible combinations; if
each table has ten records you'll see all 10,000 possible combinations.

What are the logical relationships between T_Proc, T_OCorr, T_NProc and
T_Locals? Have you assigned primary keys to all four tables? Have you defined
Relationships between them?

John W. Vinson [MVP]
 
JWV,

Thank you.
But an error occur is one time. At 1st time.
After this, work fine.
an



INSERT INTO T_PCont ( IdLocal, [Local], IdOcorr, Ocorr, NameOcorr, IdProc,
Proc, NProc )
SELECT T_Locals.IdLocal, T_Locals.Local, T_Ocorr.IdOcorr, T_Ocorr.Ocorr,
T_Ocorr.NameOcorr, T_Proc.IdProc, T_Proc.Proc, T_NProc.NProc
FROM T_Proc, T_Ocorr, T_NProc, T_Locals
WHERE (((T_Locals.IdLocal)=[Forms].[F_PCont].[txtIdLocal]) AND
((T_Locals.Local)=[Forms].[F_PCont].[txtLocal]) AND
((T_Ocorr.IdOcorr)=[Forms].[F_PCont].[txtIdOcorr]) AND
((T_Ocorr.Ocorr)=[Forms].[F_PCont].[txtOcorr]) AND
((T_Ocorr.NameOcorr)=[Forms].[F_PCont].[txtNameOcorr]) AND
((T_Proc.IdProc)=[Forms].[F_PCont].[txtIdProc]) AND
((T_Proc.Proc)=[Forms].[F_PCont].[txtProc]) AND
((T_NProc.NProc)=[Forms].[F_PCont].[cboNProc]));
 
Ok.
T_Proc has IdProc with primary key,
T_Ocorr has IdOcorr with primary key,
T_NProc has NProc with primary key, and
T_Locals has IdLocal with primary key.

The relationships in query: No.
Between them:
Through another table T_PCont without primary keys with all fields of the
tables above.

Thanks
an.


John W. Vinson said:
INSERT INTO T_PCont ( IdLocal, [Local], IdOcorr, Ocorr, NameOcorr, IdProc,
Proc, NProc )
SELECT T_Locals.IdLocal, T_Locals.Local, T_Ocorr.IdOcorr, T_Ocorr.Ocorr,
T_Ocorr.NameOcorr, T_Proc.IdProc, T_Proc.Proc, T_NProc.NProc
FROM T_Proc, T_Ocorr, T_NProc, T_Locals
WHERE (((T_Locals.IdLocal)=[Forms].[F_PCont].[txtIdLocal]) AND
((T_Locals.Local)=[Forms].[F_PCont].[txtLocal]) AND
((T_Ocorr.IdOcorr)=[Forms].[F_PCont].[txtIdOcorr]) AND
((T_Ocorr.Ocorr)=[Forms].[F_PCont].[txtOcorr]) AND
((T_Ocorr.NameOcorr)=[Forms].[F_PCont].[txtNameOcorr]) AND
((T_Proc.IdProc)=[Forms].[F_PCont].[txtIdProc]) AND
((T_Proc.Proc)=[Forms].[F_PCont].[txtProc]) AND
((T_NProc.NProc)=[Forms].[F_PCont].[cboNProc]));

You're joining *four* tables without ANY join clause or criteria. If any one
of these tables has two records in it you'll see two records in the result; if
two tables each have two records you'll see all four possible combinations; if
each table has ten records you'll see all 10,000 possible combinations.

What are the logical relationships between T_Proc, T_OCorr, T_NProc and
T_Locals? Have you assigned primary keys to all four tables? Have you defined
Relationships between them?

John W. Vinson [MVP]
 
Ok.
T_Proc has IdProc with primary key,
T_Ocorr has IdOcorr with primary key,
T_NProc has NProc with primary key, and
T_Locals has IdLocal with primary key.

The relationships in query: No.
Between them:
Through another table T_PCont without primary keys with all fields of the
tables above.

I guess I don't understand at all.

What logical Entities do these tables represent?
Why are you trying to store the data in these tables redundantly in a fifth
table?
If you open the query in datasheet view, do you see two records?
If you create four individual queries with the same criteria, do any of the
four queries return two records?

John W. Vinson [MVP]
 
What logical.../ Why are you...:
Exactly. Are redundant tables. (My ignorance)

In datasheet view:
Work fine.

With four individual queries:
Exact. Only 1st record is repeat.

Thank you
an
 
What logical.../ Why are you...:
Exactly. Are redundant tables. (My ignorance)

In datasheet view:
Work fine.

With four individual queries:
Exact. Only 1st record is repeat.

Thank you
an

That's pretty cryptic, an. Is your application working now, or not?

John W. Vinson [MVP]
 
Sorry, JWV.

If I write directly in datasheet view, work fine.
But if completing/filling up trought the form, repeat 1st record.
In 2nd record, work fine. Don't repeat, and so on.

an
 
If I write directly in datasheet view, work fine.
But if completing/filling up trought the form, repeat 1st record.
In 2nd record, work fine. Don't repeat, and so on.

Then I do not understand. I don't know anything about the contents of your
tables; I don't know what constitutes "the first" record; I don't understand
why you're doing this or what you're trying to accomplish.

I wish I could be more help, but right now I'm just completely baffled!

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

Back
Top