Hi everyone,
I'm fairly new to programming in general and have been working on a database for my fathers small company. The database is set up to automate the entry of new Work Orders and in turn set up the routing (order of events to be done to each part) for print.
I'm working on a module which determines which the previous and next task for the part is. To do this the module finds the first record where the previous field says 'none' and puts the following into variables; the ID for the part (WoTasksFID), The routing number (TaskNumber), the job that is being completed at this stage (Shop), and the task order ID (TaskOrderID). I then want it to find the first record which has the same ID for the part and has a TaskNumber that is one smaller (This is where the error in my code occurs). I record the same variables as before (this time with a prefix "Prev") and use the information to fill the previous and next fields for each record set.
Like I said, the error occurs when I am trying to match the WoTasksFID - instead of finding a field with the same WoTasksFID, it seems to choose the first field in the table no matter the value. Here's the function:
What am I doing wrong?
Thanks for any help, mango97
I'm fairly new to programming in general and have been working on a database for my fathers small company. The database is set up to automate the entry of new Work Orders and in turn set up the routing (order of events to be done to each part) for print.
I'm working on a module which determines which the previous and next task for the part is. To do this the module finds the first record where the previous field says 'none' and puts the following into variables; the ID for the part (WoTasksFID), The routing number (TaskNumber), the job that is being completed at this stage (Shop), and the task order ID (TaskOrderID). I then want it to find the first record which has the same ID for the part and has a TaskNumber that is one smaller (This is where the error in my code occurs). I record the same variables as before (this time with a prefix "Prev") and use the information to fill the previous and next fields for each record set.
Like I said, the error occurs when I am trying to match the WoTasksFID - instead of finding a field with the same WoTasksFID, it seems to choose the first field in the table no matter the value. Here's the function:
Code:
Function PreviousTask()
Dim TaskOrder As Recordset
Dim WoTasksFID As Integer 'For Current Record
Dim TaskNumber As Integer 'For Current Record
Dim Shop As String 'For Current Record
Dim TaskOrderID As Integer 'For Current Record
Dim PrevWoTasksFID As Integer 'For Previous Record
Dim PrevTaskNumber As Integer 'For Previous Record
Dim PrevShop As String 'For Previous Record
Dim PrevTaskOrderID As Integer 'For Previous Record
Dim matchfound As String
Set TaskOrder = CurrentDb.OpenRecordset("TaskOrder", dbOpenDynaset)
TaskOrder.FindFirst "[Previous] = 'none'"
Do While TaskOrder.NoMatch = False
If TaskOrder![TaskNumber] > 1 Then
WoTasksFID = TaskOrder![WoTasksFID]
TaskNumber = TaskOrder![TaskNumber]
Shop = TaskOrder![Shop]
TaskOrderID = TaskOrder![TaskOrderID]
matchfound = "no"
TaskOrder.FindFirst "[WoTasksFID] = WoTasksFID" 'finds wrong WOTaskFID????
Do While matchfound = "no"
If TaskOrder![TaskNumber] = TaskNumber - 1 Then
PrevWoTasksFID = TaskOrder![WoTasksFID]
MsgBox PrevWoTasksFID
PrevTaskNumber = TaskOrder![TaskNumber]
PrevShop = TaskOrder![Shop]
PrevTaskOrderID = TaskOrder![TaskOrderID]
TaskOrder.Edit 'Sets Next Field
TaskOrder![Next] = Shop
TaskOrder.Update
TaskOrder.FindNext "[TaskOrderID] = TaskOrderID" 'Sets Previous Field
TaskOrder.Edit
TaskOrder![Previous] = PrevShop
TaskOrder.Update
matchfound = "yes"
End If
TaskOrder.FindNext "[WoTasksFID] = WoTasksFID"
Loop
End If
TaskOrder.FindFirst "[Previous] = 'none'"
Loop
End Function
What am I doing wrong?
Thanks for any help, mango97