i have 3 tbls
tbl1:"Pending_Order"
item_id | qty
101 | 200
tbl2:"Stock_on_Hand"
item_id | qty |patch_no | Expire_date
101 | 50 |10101 | 01/05/2013
101 | 50 |10102 | 01/05/2013
101 | 150 |10106 | 01/05/2013
102 | 100 |10103 | 01/05/2013
102 | 100 |10104 | 01/05/2013
tbl3:"Order_Transaction"
item_id qty patch_no Expire_date
and i have a query but i cannot get the solution's
I need in a tbl3 :"Order_Transaction" based on others tbls like :
item_id |qty |patch_no |Expire_date
101 | 50 |10101 | 01/05/2013
101 | 50 |10102 | 01/05/2013
101 | 100 |10106 | 01/05/2013
how can i resolve it by query??
9 1289 Luuk 1,047
Recognized Expert Top Contributor - 101 | 100 |10106 | 01/05/2013
Can you explain how this number '100' is calculated from the other tables?
I need 200 unit from item code 101 in Oreder pending table
and i have same unit in stock on hand table as 3 values
i need in order transaction table transfer 200 units only
Thank you in advance
Luuk 1,047
Recognized Expert Top Contributor
"I need 200 unit from item code 101 in Oreder pending table"
OK
"and i have same unit in stock on hand table as 3 values"
seems that there's 250 units of item 101 in 'stock on hand'
"i need in order transaction table transfer 200 units only"
must be a language problem that i do not see where this 200 is coming from.....
NeoPa 32,556
Recognized Expert Moderator MVP
I'll assume this is a problem with the language. You need to understand though, that a question needs to make sense and be complete in order for people to be able to help you.
Please try to include all the necessary logic in the explanation of your question. Currently, it makes little sense.
Mr. Luuk And Mr. NeoPa
I'm really sorry my english language is not good.
I'm very sorry
But i know this site and i trust in this site
So the problem is:
1. I need to sale item_id no: 101 as 200 units
2. I have Stock from this Item "101" 3 [Patch number] in table "stock on hand"
a. first patch from item "101" has a quantity 50 units in patch x and expire date y
b. second patch from item "101" has a quantity 50 units in patch x1 and expire date y1
c. second patch from item "101" has a quantity 150 units in patch x2 and expire date y2
but i need 200 quantity units only
so : I need the query as :
I. go to first record in "stock on hand" table when item_id like same Item_id in table "pending Order" then find the quantity if the quantity in "stock on hand" table >= the quantity in "pending Order" table then type Quantity and [item_id] and [Patch_no] and [Expire date] in table "Order_Transaction".
II. if the quantity in "stock on hand" table < the quantity in "pending Order" then go to second record and calculate the variance else go to the next record and etc.
3. to be in finaly in table "Order_Transaction"
# item_id |qty |patch_no |Expire_date
1. 101 | 50 |10101 | 01/05/2013
2. 101 | 50 |10102 | 01/05/2013
3. 101 | 100 |10106 | 01/05/2013
The first record was taken as all
the second record was taken as all
the third record was calulated like(200 unit from pending - 50 unit from first record - 50 unit from second record) to be 100 units only
the table "stock on hand" should to be like:
# item_id |qty |patch_no |Expire_date
1. 101 | 50 |10106 | 01/05/2013
I hope it explained for you
thank you in advance
Luuk 1,047
Recognized Expert Top Contributor
Here's something to start with,
you should check, and improve thing!!!
(because i'm not good at acces/vba ) -
Public Function do_it()
-
Dim mydb As Database
-
Dim mytbl As Recordset
-
Dim mytbl2 As Recordset
-
Dim lastnum As Integer
-
DoCmd.SetWarnings False
-
-
DoCmd.SetWarnings True
-
Set mydb = DBEngine.Workspaces(0).Databases(0)
-
Set mytbl = mydb.OpenRecordset("Pending_Order")
-
Set mytbl2 = mydb.OpenRecordset("Stock_on_hand", dbOpenDynaset)
-
-
DBEngine.BeginTrans
-
With mytbl
-
Debug.Print "Checking order for: " & !item_id
-
mytbl2.Filter = "Item_id=" & !item_id
-
Qty_To_Check = mytbl("qty")
-
While Qty_To_Check > 0
-
With mytbl2
-
Debug.Print "Getting stock from patch_no: " & !patch_no
-
If !qty <= Qty_To_Check Then
-
DoCmd.RunSQL ("INSERT INTO Order_Transaction (Item_id, qty, patch_no, Expire_date) " _
-
& " VALUES ( " & !item_id & "," & !qty & "," & !patch_no & ",'" & !Expire_date & "')")
-
Qty_To_Check = Qty_To_Check - qty
-
Else
-
DoCmd.RunSQL ("INSERT INTO Order_Transaction (Item_id, qty, patch_no, Expire_date) " _
-
& " VALUES ( " & !item_id & "," & Qty_To_Check & "," & !patch_no & ",'" & !Expire_date & "')")
-
Qty_To_Check = 0
-
End If
-
End With
-
Wend
-
End With
-
DBEngine.CommitTrans
-
mytbl.Close
-
mytbl2.Close
-
Set mytbl = Nothing
-
Set mytbl2 = Nothing
-
Set mydb = Nothing
-
-
End Function
-
Rabbit 12,516
Recognized Expert Moderator MVP
Assuming that patch is unique, you can do this with 3 queries. An insert, an update, and a delete.
In each one you join the table to itself to get a running sum so you can calculate how much you need to fulfill the order.
NeoPa 32,556
Recognized Expert Moderator MVP
@Ahmed
We have no wish to criticise or penalise lack of language skills. Unfortunately, sometimes they are penalised automatically simply because we can't help easily unless we understand what it is you're asking for. I suspect your latest post goes some way to help with that, but even if it's still unclear - we won't be criticising you for that. Good luck.
PS. If you can understand Rabbit's post then I can certainly say he's very clever and you can be sure his advice is worth exploring.
@Rabbit
Considering the language limitations here, I expect your suggestion is presented in too cryptic a form to be (easily) understood.
Rabbit 12,516
Recognized Expert Moderator MVP
I tend to be cryptic at first to see how far they can get and explain further if necessary.
Note that my suggestion is for fulfilling one order at a time, if you need to fulfill multiple orders of the same item at the same time, then you need to do a running sum on that as well and that just becomes very complicated. In that situation, it would be best to go with the more unambiguous VBA code.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: SomeDude |
last post by:
Lo group,
I would like to know if it is possible to a (string) replace on
existing records based on a given pattern.
Let's say I have a table containing the following records (strings):...
|
by: Matt |
last post by:
Hi everyone, still pretty new to MySQL. I was
wondering if there is a way to automatically filter
records based on a mysql userlogin name??
I have serveral databases that I want to combine
in...
|
by: arthur-e |
last post by:
How can you select records based on more than one combo box -
I have a combobox that selects records based on name
(I'm sure this has been asked a thousand times - web site answer/link
could be...
|
by: DS |
last post by:
Hi Guys (and ladies):
I have a parameter query in A2K that asks for records based on certain
criteria. It returns the name and address fields of each record. I
usually get about 5 to 10 records...
|
by: Eugene Anthony |
last post by:
I have a table that has a DateTime column which uses a DataTime
datatype. How do I retrieve a range of records based on the month and
year using ms sql?
Eugene Anthony
*** Sent via...
| |
by: BEETHOVEN |
last post by:
I have an option group called Issue_Type on my main form
F1_Member_Demographics_Main. When I select one of the 3 options on the
main form from the option group Issue_Type I want to limit the sub...
|
by: cehlinger |
last post by:
I am trying to add multiple records based on a date range. I found some examples and have tried them but am getting errors and I can't seem to figure out what the problem is. I am not a VBA...
|
by: lev9shun |
last post by:
Hi all,
I have a reporting table that I use for my reports but would like to filter(flag) records based certain Medical conditions.
Example of reporting table:
ID Name MedCond Reported...
|
by: kffacs |
last post by:
Multiple rows based on a date range
I have an MSAccess 2007 DB to record our employees Personal Days Off (PDO). Until now I have only had a form to record each single day taken. This results in...
|
by: Yoni Hasid |
last post by:
Hello,
I am struggling with finding a solution on how to assign numerical values to text records based on various criteria. I have a table with survey responses where each column has text records...
|
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,...
| |
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...
|
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: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
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,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
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...
| |
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |