473,385 Members | 1,727 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,385 software developers and data experts.

SQL append query help

111 100+
i have code that loops through a recordset and checks to see if a condition is true. If it's true, i want to send that record to a different table, but im having trouble doing so.

i have:

Expand|Select|Wrap|Line Numbers
  1. if x = true then
  2. DoCmd.RunSQL "INSERT INTO [tblReady] SELECT [sheet1].* FROM [sheet1] WHERE (([sheet1].[Vendor Number])= recordset.[Vendor Number])"
but when the condition is true, its asking me to enter a value for "recordset.[Vendor Number].

How could i change it so that when the condition is true, it just takes the current record in the recordset and adds that to the new table?
Oct 10 '07 #1
3 1745
Neekos
111 100+
basically - i just need to know how to reference the current record in an ADO recordset.
Oct 10 '07 #2
Neekos
111 100+
figured it out. forgot about the syntax for referencing a variable.

here's what works:

Expand|Select|Wrap|Line Numbers
  1. DoCmd.RunSQL "INSERT INTO [tblReady] SELECT [sheet1].* FROM [sheet1] WHERE (([sheet1].[Vendor Number])= " & recordset.Fields(4) & ")"
Oct 10 '07 #3
nico5038
3,080 Expert 2GB
figured it out. forgot about the syntax for referencing a variable.

here's what works:

Expand|Select|Wrap|Line Numbers
  1. DoCmd.RunSQL "INSERT INTO [tblReady] SELECT [sheet1].* FROM [sheet1] WHERE (([sheet1].[Vendor Number])= " & recordset.Fields(4) & ")"
Well done :-)
You could have used:
Expand|Select|Wrap|Line Numbers
  1. DoCmd.RunSQL "INSERT INTO [tblReady] SELECT [sheet1].* FROM [sheet1] WHERE (([sheet1].[Vendor Number])= " & recordset![Vendor Number] & ")"
when the field has the same name in the recordset. Thus it's easier to understand and when a field is added or removed in the select statement, you won't have to change the fieldnumber.
Also try to drop the usage of spaces in fieldnames. It will reduce the number of errors when coding as you can drop the [ and ] :-)

Nic;o)
Oct 11 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: John | last post by:
Hi - I am trying to perform a simple append query, with no luck. I have a table (MktPrices) that has the following fields: BondID, PriceDate, Price. The objective is to allow the user to input a...
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...
2
by: Danny | last post by:
I want to extract a subset of fields from one table into another the master table has many fields the subset has about half, but still many. Is there a way I can just append the master into the...
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: 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...
13
by: Lee | last post by:
Hello All, First of all I would like to say thank you for all of the help I have received here. I have been teaching myself Access for about 4 years now and I've always been able to find a...
5
by: solar | last post by:
I have copied a function that appends from table orders2 into table orders1 the row that has the value SubOrder = True in the table orders2. This function finds the highest ordered in the table...
10
by: pythonnoob | last post by:
Hello everyone. New to python as well as this forum, but i must say ive learned a but already reading through some posts. Seems to be a pretty helpful community here. Before i post a question...
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...
4
by: franc sutherland | last post by:
Hello, I am using Access 2003. I am having trouble trapping the "can't append all the records in the append query" error message when appending data to a query from a table which is linked to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.