473,547 Members | 2,532 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

append question

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 orders2.
But I want to find the highest ordered in the table orders2 instead.
In short, I want to append the order from the table orders2 into the
table orders1 and this order to get the next highest ordered.Somehow I
canot manage it.Can you help me :
Below is the working function that gets the highest ordered in the
tabnle ordersd2:
Can you help me amend it with my new requirement?My own function is a
mess so i do not show it i am showing only the working function that i
have copied.

'target table : orders1
' source table : orders2

Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim strSQL As String
Dim lngMaxID As Long

Set dbs = CurrentDb

' Get highest OrderID
strSQL = "SELECT Max(Orders2.Ord erID) AS MaxID " & _
"FROM Orders2 LEFT JOIN Orders1 " & _
"ON Orders2.OrderID = Orders1.OrderID " & _
"WHERE Orders1.OrderID Is Null AND Orders2.SubOrde r=True"
Set rst = dbs.OpenRecords et(strSQL, dbOpenDynaset)
If IsNull(rst!MaxI D) Then
MsgBox "No records to append.", vbInformation
rst.Close
Set rst = Nothing
Set dbs = Nothing
Exit Function

End If

lngMaxID = rst!MaxID
rst.Close

' Insert orders
strSQL = "INSERT INTO Orders1 " & _
"SELECT * FROM Orders2 " & _
"WHERE Orders2.OrderID = " & lngMaxID
dbs.Execute strSQL

Jan 12 '06 #1
5 2236
"solar" <sp*******@gmai l.com> wrote in message
news:11******** *************@g 49g2000cwa.goog legroups.com...
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 orders2.
But I want to find> canot manage it.Can you help me :
Below is the working function that gets the highest ordered in the
tabnle ordersd2:
Can you help me amend it with my new requirement?My own function is a
mess so i do not show it i am showing only the working function that i
have copied.

'target table : orders1
' source table : orders2

Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim strSQL As String
Dim lngMaxID As Long

Set dbs = CurrentDb

' Get highest OrderID
strSQL = "SELECT Max(Orders2.Ord erID) AS MaxID " & _
"FROM Orders2 LEFT JOIN Orders1 " & _
"ON Orders2.OrderID = Orders1.OrderID " & _
"WHERE Orders1.OrderID Is Null AND Orders2.SubOrde r=True"
Set rst = dbs.OpenRecords et(strSQL, dbOpenDynaset)
If IsNull(rst!MaxI D) Then
MsgBox "No records to append.", vbInformation
rst.Close
Set rst = Nothing
Set dbs = Nothing
Exit Function

End If

lngMaxID = rst!MaxID
rst.Close

' Insert orders
strSQL = "INSERT INTO Orders1 " & _
"SELECT * FROM Orders2 " & _
"WHERE Orders2.OrderID = " & lngMaxID
dbs.Execute strSQL


Perhaps forget about the function for a minute and concentrate on the
correct sql - you can do it all in one statement. However, with Orders1,
Orders2, Order By, etc I cannot quite see what you are doing.

The sql below, finds the most recent order in Orders2 which does not occur
in Orders1 and which has SubOrder=True, and appends this to Orders1. The
"most recent order" means sort by date and then by ID if more than one
occurs on the same date. You could obviously change this to give you the
highest value order or whatever you want - it is this part I didn't
understand.

Anyway, here is the single sql statement which should do the lot:

INSERT INTO Orders1
SELECT TOP 1 Orders2.*
FROM Orders2 LEFT JOIN Orders1
ON Orders2.OrderID =Orders1.OrderI D
WHERE Orders1.OrderID Is Null
AND Orders2.SubOrde r=True
ORDER BY Orders2.OrderDa te DESC,
Orders2.OrderID DESC
Jan 12 '06 #2
I believe you misspoke in your statement. You are currently getting the
highest order number in Table2 that does not exist in Table1. I assume
you're wanting to add to Table1 any order in Table2 that doesn't exist in
Table1. If that's the case, you don't need the Max statement. Instead, just
let the first query return all records from Table2 that don't match Table1.
Use that query as the source for the Append query and you will then add all
records from Table2 to Table1 that don't currently exist in Table1. This
will be ALL records that don't currently exist in Table1, regardless of how
high their OrderID value is.

However, if you only want to add records with order numbers greater than the
highest order number in Table1, you can do this by using the following query
in lieu of your first query then use this new query as the source of the
Append query.

strSQL = "SELECT Orders2.* " & _
"FROM Orders2 " & _
"WHERE Orders2.OrderID > DMax(""OrderID" ", ""Table1"") ;"
--
Wayne Morgan
MS Access MVP
"solar" <sp*******@gmai l.com> wrote in message
news:11******** *************@g 49g2000cwa.goog legroups.com...
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 orders2.
But I want to find the highest ordered in the table orders2 instead.
In short, I want to append the order from the table orders2 into the
table orders1 and this order to get the next highest ordered.Somehow I
canot manage it.Can you help me :
Below is the working function that gets the highest ordered in the
tabnle ordersd2:
Can you help me amend it with my new requirement?My own function is a
mess so i do not show it i am showing only the working function that i
have copied.

'target table : orders1
' source table : orders2

Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim strSQL As String
Dim lngMaxID As Long

Set dbs = CurrentDb

' Get highest OrderID
strSQL = "SELECT Max(Orders2.Ord erID) AS MaxID " & _
"FROM Orders2 LEFT JOIN Orders1 " & _
"ON Orders2.OrderID = Orders1.OrderID " & _
"WHERE Orders1.OrderID Is Null AND Orders2.SubOrde r=True"
Set rst = dbs.OpenRecords et(strSQL, dbOpenDynaset)
If IsNull(rst!MaxI D) Then
MsgBox "No records to append.", vbInformation
rst.Close
Set rst = Nothing
Set dbs = Nothing
Exit Function

End If

lngMaxID = rst!MaxID
rst.Close

' Insert orders
strSQL = "INSERT INTO Orders1 " & _
"SELECT * FROM Orders2 " & _
"WHERE Orders2.OrderID = " & lngMaxID
dbs.Execute strSQL

Jan 12 '06 #3
Thank you very much for the 2 replies i have received.I see that both
replies might have helped me if i was more clear of what i intend to
do.I will be extremely grateful for your help, i am stuck with this
problem.So,in both tables, orders2 and orders1, there is a YesNo field
called Suborder.Whenev er there is an order in the table orders2, with a
field Suborder = Yes,i want to append this order into
the table orders1 and give it the next highest number.For example:In
table order2 there is an order number 7443 having a field Suborder =
Yes.In the table ordrrs1 the last order number is 7.
I want to append the order 7443 into the table orders2 and give it the
next highest order number which will be 8 in my case.I am showing a
part of my function that does the oppposite, gets the highest number in
the orders2.
Could you help me rewrite the function?

Jan 13 '06 #4
Thank you very much for the 2 replies i have received.I see that both
replies might have helped me if i was more clear of what i intend to
do.I will be extremely grateful for your help, i am stuck with this
problem.So,in both tables, orders2 and orders1, there is a YesNo field
called Suborder.Whenev er there is an order in the table orders2, with a
field Suborder = Yes,i want to append this order into
the table orders1 and give it the next highest number.For example:In
table order2 there is an order number 7443 having a field Suborder =
Yes.In the table ordrrs1 the last order number is 7.
I want to append the order 7443 into the table orders2 and give it the
next highest order number which will be 8 in my case.I am showing a
part of my function that does the oppposite, gets the highest number in
the orders2.
Could you help me rewrite the function?

Jan 13 '06 #5
After the line

lngMaxID = rst!MaxID

Add the following does what you want:

lngOrders1NewID = DMax("[OrderID]", "[Orders1]") + 1

Then in your SQL Append Query, you'll need to specify the fields instead of
using the * so that you can insert the new ID value.

"INSERT INTO Orders1 " & _
"SELECT " & lngOrders1NewID & " As NewID, Field2, Field3, Field4 " & _
"WHERE Orders2.OrderID = " & lngMaxID & ";"

You would concatenate in the ID field in the order (left to right) that it
is in the Orders1 table. List the other fields from Orders2 as needed to get
the rest of the information.

--
Wayne Morgan
MS Access MVP
"solar" <sp*******@gmai l.com> wrote in message
news:11******** **************@ g43g2000cwa.goo glegroups.com.. .
Thank you very much for the 2 replies i have received.I see that both
replies might have helped me if i was more clear of what i intend to
do.I will be extremely grateful for your help, i am stuck with this
problem.So,in both tables, orders2 and orders1, there is a YesNo field
called Suborder.Whenev er there is an order in the table orders2, with a
field Suborder = Yes,i want to append this order into
the table orders1 and give it the next highest number.For example:In
table order2 there is an order number 7443 having a field Suborder =
Yes.In the table ordrrs1 the last order number is 7.
I want to append the order 7443 into the table orders2 and give it the
next highest order number which will be 8 in my case.I am showing a
part of my function that does the oppposite, gets the highest number in
the orders2.
Could you help me rewrite the function?

Jan 14 '06 #6

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

Similar topics

3
1868
by: J Krugman | last post by:
This question refers to the DOM. I would like to dynamically append some small amount of text to the all-text content of a <pre> node. I suppose that I could extract the existing content, and replace the <pre> node in question with a new <pre> node that has the extended content. But the existing content is longish, and it seems to me...
4
2569
by: yaffa | last post by:
dear folks, i'm trying to append a semicolon to my addr string and am using the syntax below. for some reason the added on of the ; doesn't work. when i print it out later on it only shows the original value of addr. addr = incident.findNextSibling('td') addr.append('%s;') thanks
25
7565
by: Yves Glodt | last post by:
Hello, if I do this: for row in sqlsth: ________pkcolumns.append(row.strip()) ________etc without a prior:
5
4902
by: Barn Yard | last post by:
good morning, im still kind of new to VBA but I have learned some interesting things so far. Right now I am normalizing my survey database so I'm having to run an append query for each question(300 in some surveys). WARNING: I've very new at this so this may not look right. i hope it gives the idea of what I'm trying to accomplish. ...
1
3401
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; _____________________________________________________ SELECT "criteria"
5
5351
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 if I append the data 3 times in succession, it copies the same data over 3x. Now I have copies in triplicate. It used to only transfer records...
3
4810
by: Freddy Coal | last post by:
Hi, I would like append strings to a binary file, but I don´t understand how make that. I try with: FileOpen(1, Folder_Trabajo & "\Toma_Trazas.FC", OpenMode.Append, OpenAccess.Write, OpenShare.Default) FilePut(1, "My string") '<****** ERROR IN THIS LINE ****** FileClose(1)
13
4743
by: HMS Surprise | last post by:
Trying not to be a whiner but I sure have trouble finding syntax in the reference material. I want to know about list operations such as append. Is there a pop type function? I looked in tutorial, language reference, and lib for list, append, sequence. Is there a place where us doofi ( who may not have our heads out in the sunlight) may find...
2
4118
by: sj | last post by:
Situation: I have 2 tables, parent table (Invoice) and child table (InvoiceDetails) that is link by InvID in the child. Requirement: Need to do one-time append of information to another table of the similar structure. Problem: When main table is append to the new table, it will bear a new ID.
42
1747
by: Armin | last post by:
Hi, just a dumb question. Let a = Why is the value of a.append(7) equal None and not ?? --Armin
0
7510
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7703
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7947
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7797
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6032
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5081
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3473
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1923
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1050
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.