Hi.
Working on an application that at current works as written, but slow because I wrote vba code to open data as recordsets and scroll through to get my results. I am sure there is a sql solution that would be faster but I don't know how.
Two tables, table one indicates requirements:
Due Date, Item, Qty Required
1/1/06, 123, 10
1/10/06, 123, 5
And Available
Item, On Hand
123, 12
So my result would be to change Table One to read
Due Date, Item, Qty Required
1/1/06, 123, 0
1/10/06, 123, 3
And Table 2 with
Item, On Hand
123, 0
Any advice would be appreciated. As I mention it works using the code, but the code is slow and runs one record in each table at a time. The code follows if interested:
Function Adjudicate()
Set Reqs = CurrentDb.OpenRecordset("BaseRequirements")
Reqs.MoveFirst
Dim MySql As String
Dim UQ As Double
Dim FD As Date
Dim IQ As Integer
IQ = 0
While Not Reqs.EOF()
X = Reqs.Item
Y = Reqs.Due
Z = Reqs.Required
MySql = ""
MySql = MySql & "SELECT Available.ItemNumber, Available.type, Available.When, Available.Reference, Available.Qty FROM Available "
MySql = MySql & "WHERE (((Available.ItemNumber)='" & Trim(X) & "') And Available.Qty > 0);"
Set Avail = CurrentDb.OpenRecordset(MySql)
While Not Avail.EOF() And Z > 0
If Avail.Qty >= Z Then
UQ = Z
FD = Avail.When
Avail.Edit
Avail.Qty = Avail.Qty - UQ
Avail.Update
Else
UQ = Avail.Qty
Avail.Edit
Avail.Qty = Avail.Qty - UQ
Avail.Update
End If
Z = Z - UQ
Avail.MoveNext
Wend
Reqs.Edit
Reqs.Required = Z
If Z = 0 Then
Reqs.Fulfilment = FD
End If
Reqs.Update
Reqs.MoveNext
Wend
End Function
There Are 10 Types Of People In The world:
Those That Understand BINARY And Those That Don’t.
Working on an application that at current works as written, but slow because I wrote vba code to open data as recordsets and scroll through to get my results. I am sure there is a sql solution that would be faster but I don't know how.
Two tables, table one indicates requirements:
Due Date, Item, Qty Required
1/1/06, 123, 10
1/10/06, 123, 5
And Available
Item, On Hand
123, 12
So my result would be to change Table One to read
Due Date, Item, Qty Required
1/1/06, 123, 0
1/10/06, 123, 3
And Table 2 with
Item, On Hand
123, 0
Any advice would be appreciated. As I mention it works using the code, but the code is slow and runs one record in each table at a time. The code follows if interested:
Function Adjudicate()
Set Reqs = CurrentDb.OpenRecordset("BaseRequirements")
Reqs.MoveFirst
Dim MySql As String
Dim UQ As Double
Dim FD As Date
Dim IQ As Integer
IQ = 0
While Not Reqs.EOF()
X = Reqs.Item
Y = Reqs.Due
Z = Reqs.Required
MySql = ""
MySql = MySql & "SELECT Available.ItemNumber, Available.type, Available.When, Available.Reference, Available.Qty FROM Available "
MySql = MySql & "WHERE (((Available.ItemNumber)='" & Trim(X) & "') And Available.Qty > 0);"
Set Avail = CurrentDb.OpenRecordset(MySql)
While Not Avail.EOF() And Z > 0
If Avail.Qty >= Z Then
UQ = Z
FD = Avail.When
Avail.Edit
Avail.Qty = Avail.Qty - UQ
Avail.Update
Else
UQ = Avail.Qty
Avail.Edit
Avail.Qty = Avail.Qty - UQ
Avail.Update
End If
Z = Z - UQ
Avail.MoveNext
Wend
Reqs.Edit
Reqs.Required = Z
If Z = 0 Then
Reqs.Fulfilment = FD
End If
Reqs.Update
Reqs.MoveNext
Wend
End Function
There Are 10 Types Of People In The world:
Those That Understand BINARY And Those That Don’t.