[AccessD] FindFirst Error

Stuart McLachlan stuart at lexacorp.com.pg
Wed May 23 16:10:05 CDT 2012


In any SQL or criteria string, you need to delimit text strings. You can use either single quotes 
of double quotes to do this.   I find  single quotes easiest to use in code since it avoids 
complications with the standard use of double quotes in VBA.   

Using single quote:
rstRS.FindFirst "[EmployeeTimesID] = '" & strKey & "'"

Using double quote:
rstRS.FindFirst "[EmployeeTimesID] = '" & Chr$(34) & strKey & chr$(34)
or
rstRS.FindFirst "[EmployeeTimesID] = """ & strKey & """"

Actually,  it is better practice to do this:
strFilter = "[EmployeeTimesID] = '" & strKey & "'"
rstRS.FindFirst strFilter

That way, if youy are having problems you can always throw in a "Debug.Print strFilter" of 
"Msgbox strFilter" to see exactly what is going on.

StrFilter should return
 [EmployeeTimesID] = '5/21/2012Heather Hanson'
or 
 [EmployeeTimesID] = "5/21/2012Heather Hanson"

yours would return:
[EmployeeTimesID] = 5/21/2012Heather Hanson

-- 
Stuart

On 23 May 2012 at 11:14, Dale Kalsow wrote:

> Good Afternoon Everyone,
>  
> I have the following code that is giving me a Run-time error '3077' Syntax error (missing operator) in expression. on the FindFirst line.  Can anyone see why?  
> strkey = 5/21/2012Heather Hanson
>  
> Is access not liking the space in field?
>  
> Thanks!
>  
> Set dbsDB = DBEngine(0)(0)
>     Set rstRS = dbsDB.OpenRecordset("tblEmployeeTimes", dbOpenDynaset)
>     Set rstRsNew = dbsDB.OpenRecordset("qryKeyCardImport", dbOpenDynaset)
>     
>     rstRsNew.MoveFirst
>     
>     Do While Not rstRsNew.EOF
>         strKey = Format(rstRsNew![Time], "Short Date") & 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] = Format(rstRsNew![Time], "Short Date")
>                     rstRS![[EmployeeTimesName]] = Trim(rstRsNew![Employee])
>                     rstRS![EmployeeTimesIn] = Format(rstRsNew![Time], "Medium Time")
>                     .Update
>                   End With
>             End If
>             rstRsNew.MoveNext
>             
>         Loop
> -- 
> AccessD mailing list
> AccessD at databaseadvisors.com
> http://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com
> 

--
Stuart McLachlan

Ph:    +675 340 4392 
Mob: +675 7100 2028
Web: http://www.lexacorp.com.pg




More information about the AccessD mailing list