Matching field value to a variable

mango97

Registered User.
Local time
Today, 01:27
Joined
Jul 24, 2014
Messages
40
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:

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
 
TaskOrder.FindFirst "[WoTasksFID] = " & WoTasksFID 'finds wrong WOTaskFID????
 
For being quite new to programming you are very neat and seem to sit down and plan your program out a lot. You're on an extremely good track! :)
 
Hi BluIshDan,

That works! Should I be using that syntax for my field searches?
 
Here is what happened. It was because you were concatenating a string with a variable value.

What you were initialling building was: "[WoTasksFID] = WoTasksFID"
Which will send exactly as it shows because it thinks that WoTasksFID is part of the string, not a variable.

What worked was: "[WoTasksFID] = " & WoTasksFID
Which will combine the string: "[WoTasksFID] = "
with the value contained in the WoTasksFID variable.
 
Ah, thankyou again. Saved me hours of frustration. :P
 
Again, great white spacing and tabbing. I also noticed that you separated your variables by use/type, which is also amazing. lol Great job :)
 

Users who are viewing this thread

Back
Top Bottom