About to go crazy, whats wrong with this?

tembenite

Registered User.
Local time
Yesterday, 22:57
Joined
Feb 10, 2005
Messages
38
Okay, I'm new to this and about to go crazy. Whats wrong with the code below?


Function addDays(employID As Long, daType As String, daEXPDATE As Date, daREMARKS As String)
Dim daNOW As Date
Dim daDAYS As Double
Dim daSEARCH As String
Dim rst As Recordset
daNOW = Now()
daYEARS = Int((Now() - (DLookup("[hiredate]", "employees", "ID = " & employID))) / 365.25) ' Number Emp has been in company
daSEARCH = "begyear <= " & daYEARS & ", uptoyear > " & daYEARS & ", type = '" & daType & "' "
CurrentDb.Recordsets("TableOfDaysEarned").FindFirst (daSEARCH) '<-- I keep getting an error "Item Not Found in Collection"


There is one item in table "TableOfDaysEarned" that meets this criteria. I have verified it several times. I have even tried simplifying the query to:
daSEARCH = "type ='v'" of which, there are 3 entries. Still, I get the same error "Item not found in collection".
 
t,

You have to open the recordset first:

Set rst = CurrentDb.OpenRecordset("TableOfDaysEarned")

Wayne
 
You might also be better off using the DateDiff function to calculate daYears and replace Now() with Date() instead to prevent other errors
 
it's also good practice to declare your daYEARS variable.
 

Users who are viewing this thread

Back
Top Bottom