[AccessD] FindFirst Error

Jim Dettman jimdettman at verizon.net
Wed May 23 14:45:14 CDT 2012


 rstRS.FindFirst "[EmployeeTimesID] = " & strKey

Should be: 

 rstRS.FindFirst "[EmployeeTimesID] = " & chr$(34) & strKey & chr$(34)

The key format should be whatever you expect to find in EmployeeTimesID


Also on this:

 Set dbsDB = DBEngine(0)(0)
    'Set db = CurrentDb - Can substitue for above line but slower and will
not handle linked files.

You might want to give this a gander:

CurrentDB() vs. dbEngine.Workspaces(0).Databases(0) and an alternative
http://rdsrc.us/magJ9c


 And on the comment of not being able to handle linked tables, I think what
was meant that you can't open a linked table as a type table (you can open
it if you use a dynaset though fine).

Jim.

-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Dale Kalsow
Sent: Wednesday, May 23, 2012 03:16 PM
To: Access Developers discussion and problem solving
Subject: Re: [AccessD] FindFirst Error

No matter what I try I still get an error on the findfirst command the
second time around.  I get an error if the # are there or if they are not. 
I have even taken the slashes out of the date, but it has not helped.
 
Here is the current format of the key:  5212012HeatherHanson
 
Here is the current code:
 
 Set dbsDB = DBEngine(0)(0)
    'Set db = CurrentDb - Can substitue for above line but slower and will
not handle linked files.
    
    ' Open database
    Set rstRS = dbsDB.OpenRecordset("tblEmployeeTimes", dbOpenDynaset)
    Set rstRsNew = dbsDB.OpenRecordset("qryKeyCardImport", dbOpenDynaset)
    
    rstRsNew.MoveFirst
    
    Do While Not rstRsNew.EOF
        strKey = Replace(Format(rstRsNew![Time], "Short Date"), "/", "") &
Replace(Trim(rstRsNew![Employee]), " ", "")
        rstRS.FindFirst "[EmployeeTimesID] = " & strKey
        If Not rstRS.NoMatch Then
                With rstRS
                    .Edit
                    rstRS![EmployeeTimesOut] = Format(rstRsNew![Time],
"Medium Time")
                    .Update
                End With
            Else
                With rstRS
                    .AddNew
                    rstRS![EmployeeTimesID] = strKey
                    rstRS![EmployeeTimesDate] = DateValue(rstRsNew![Time])
                    rstRS![EmployeeTimesName] = Trim(rstRsNew![Employee])
                    rstRS![EmployeeTimesIn] = TimeValue(rstRsNew![Time])
                    .Update
                End With
            End If
            rstRsNew.MoveNext
            
        Loop
        
        varTmp = SysCmd(acSysCmdClearStatus)
        MsgBox "The EmployeeTimes file has been updated", vbOKOnly +
vbInformation, "Parts Master"
        
        
        rstRS.Close
        rstRsNew.Close
        
        dbsDB.Close
        
        Set rstRS = Nothing
        Set rstRsNew = Nothing
        
        Set dbsDB = Nothing


________________________________
From: Gustav Brock <gustav at cactus.dk>
To: accessd at databaseadvisors.com 
Sent: Wednesday, May 23, 2012 1:57 PM
Subject: Re: [AccessD] FindFirst Error

Ouch, dates as strings ...

Still, this has to be corrected:

rstRS![[EmployeeTimesName]] 

/gustav


>>> dkalsow at yahoo.com 23-05-12 20:30 >>>
The entire field is defined as a string in the table.  Also, the first time
around (when the table is empty) the first record is created without an
error.

-- 
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com
-- 
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com




More information about the AccessD mailing list