473,320 Members | 1,876 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Append Query Problem

I have a form with a subform. When there are no entries in the
subform, I have an append query which makes a default entry in the
subform (for what I am doing there needs to be at least one value in
the subform).

The code in the form is this:

Private Sub Form_AfterInsert()
If Me.strWholeStr = 0 Then
DoCmd.SetWarnings False
DoCmd.OpenQuery "AddNewPart"
DoCmd.SetWarnings True
End If
End Sub

So if the user unchecks a box saying there will be no entries in the
sub form it runs the append query.

Here is the code for my append query...

INSERT INTO 4ptTable ( ptstrKey )
SELECT [strKey]
FROM 3strTable;

My problem is whenever the append query is run, it adds a record to
EVERY record in the table... not just the record I am currently working
on. there must be a way to code it so it only appends the record that
is curently being worked on.

My level of SQL is very basic so please explain any code you suggest.

Cheers!
James

Jul 28 '06 #1
1 2341
"James Hallam" <ja******@googlemail.comwrote in
news:11**********************@m73g2000cwd.googlegr oups.com:
I have a form with a subform. When there are no entries in
the subform, I have an append query which makes a default
entry in the subform (for what I am doing there needs to be at
least one value in the subform).

The code in the form is this:

Private Sub Form_AfterInsert()
If Me.strWholeStr = 0 Then
DoCmd.SetWarnings False
DoCmd.OpenQuery "AddNewPart"
DoCmd.SetWarnings True
End If
End Sub

So if the user unchecks a box saying there will be no entries
in the sub form it runs the append query.

Here is the code for my append query...

INSERT INTO 4ptTable ( ptstrKey )
SELECT [strKey]
FROM 3strTable;

My problem is whenever the append query is run, it adds a
record to EVERY record in the table... not just the record I
am currently working on. there must be a way to code it so it
only appends the record that is curently being worked on.

My level of SQL is very basic so please explain any code you
suggest.

Cheers!
James
Your query needs to have a filter (WHERE CLAUSE), which limits
the appends to the value on your mainform.
(change mainform to the real name of your mainform.)

INSERT INTO 4ptTable ( ptstrKey )
SELECT [strKey]
FROM 3strTable
WHERE [strKey] = Forms!mainform!strkey;

However there are simpler ways of doing this.
INSERT INTO 4ptTable ( ptstrKey )
VALUES (Forms!mainform!strkey);

The BEST way however, is to forego a query altogether, but use
the parent - child relation between the form and subform to
populate the record.

Private Sub Form_AfterInsert()
If Me.strWholeStr = 0 Then
me.subformname.form.ptstrkey = me!strkey
End If
End Sub

--
Bob Quintal

PA is y I've altered my email address.

--
Posted via a free Usenet account from http://www.teranews.com

Jul 28 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: PMB | last post by:
Thank you in advance for any and all assistance. I'm trying to use a make table query to pull the last transactionID, so I can use an append query to reset the transactionID to the next...
7
by: | last post by:
I found similiar issues in MS-KB but nothing that helped me; got the Windows and Office updates from the MS website but that hasn't changed the behavior of this problem, and I don't see anything...
1
by: Aaron | last post by:
Hello fellow programmers, I am trying to run an append/update query from code, a command button on a form initiates the queries. the format i am using is; ...
1
by: Kristina | last post by:
I'm trying to run multiple append queries in an Access front end that append data from tables in a .mdb into tables in SQL Server 2000. My Access front end has a link to both tables, the .mdb and...
1
by: David Barger | last post by:
Greetings, It appears that an Append Query I run in Access XP is randomly failing to append a field. I have payroll data being entered into a payroll database. This data is exported daily to...
5
by: Michael C via AccessMonster.com | last post by:
Hello, I have a table that I am appending 3 seperate tables into. My main problem is that each time I append the data, it simply adds to the data already there. That might sound ok, except that...
4
by: pmacdiddie | last post by:
I have an append query that needs to run every time a line item is added to a subform. The append writes to a table that is the source for a pull down box. Problem is that it takes 5 seconds to...
7
by: wade.wall | last post by:
Hi all, I am having a problem appending data to an existing table. I have two tables with identical fields and I want to append the data from one table (T2) to the first (T1). T1 has 136...
4
by: Scott12345 | last post by:
Hi, here is my situation, I have a DB that tracks machine downtime (30 machines) per day. Several users will update this through the day. I created an append query that creates 30 dummy values and...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.