Link to home
Create AccountLog in
Avatar of PeterBaileyUk
PeterBaileyUk

asked on

search string syntax for findfirst in access

I am having trouble getting the syntax correct to create sqlstr for the findfirst method. I need to find cwcode where empname=username and clientname="michelin"
Private Sub SetViewed()

Dim db As Database
Set db = CurrentDb

Dim CWlogRS As dao.Recordset



    Set CWlogRS = db.OpenRecordset("Tblsmartview", dbOpenDynaset)

    
    mvriscode = Forms!cw_client_matching_form.[mvris code].Value

    
 






If Me.ChkLogView = False Then



Else

   sqlstr = "[CWCode] = '" + mvriscode + "'" And ClientName = "michelin" And empname = Environ("username")
    CWlogRS.FindFirst sqlstr
    
    If CWlogRS.NoMatch Then
        CWlogRS.AddNew
        CWlogRS.Fields("cwcode").Value = mvriscode
    Else
        CWlogRS.Edit
    End If
'
'
    CWlogRS.Fields("ClientName").Value = "Michelin"
    CWlogRS.Fields("viewdate").Value = Date
    CWlogRS.Fields("empName").Value = Environ("username")
    CWlogRS.Update





End If

End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of peter57r
peter57r
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of PeterBaileyUk
PeterBaileyUk

ASKER

:)