Results 1 to 5 of 5
  1. #1
    jtm013 is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Aug 2014
    Posts
    117

    Findfirst problem with Environ as criteria.

    Hello,



    I am having trouble with my usage of findfirst.
    Code is shown below. This code will append the login name to the user log.


    Code:
    Set rst1 = CurrentDb.OpenRecordset("tLogUser", dbOpenDynaset)                
              If rst1.RecordCount <> 0 Then
                        With rst1
                            .FindFirst "[LocationName]" = Environ("ComputerName")
                            If Not .NoMatch Then
                                .Edit
                                    .Fields("LoginName") = " & Me.cboEmployee.Value & "
                                .Update
                                Else
                                MsgBox "No Match Found.", vbInformation, "System Failure"
                            End If
                        End With
                    End If
    The problem is that when this is run it present a no match situation even though there is a corresponding record in the listed table "tlogUser"

  2. #2
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,529
    Wrong syntax. Try

    .FindFirst "[LocationName] = '" & Environ("ComputerName") & "'"
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,529
    Oh, and more efficient:

    Set rst1 = CurrentDb.OpenRecordset("SELECT * FROM tLogUser WHERE [LocationName] = '" & Environ("ComputerName") & "'", dbOpenDynaset)

    If Not rst1.EOF
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    jtm013 is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Aug 2014
    Posts
    117
    Awesome! Thank you!!! Works great!

  5. #5
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,529
    No problemo!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. .FindFirst problem
    By akhmadahdiyat in forum Programming
    Replies: 2
    Last Post: 11-29-2013, 12:27 AM
  2. FINDFIRST Multiple criteria
    By trigirl67 in forum Forms
    Replies: 1
    Last Post: 01-31-2012, 02:02 PM
  3. FindFirst with multiple fields in criteria
    By compooper in forum Programming
    Replies: 5
    Last Post: 07-22-2011, 10:29 AM
  4. Problem with Environ function in 2003 SP3
    By wgreynol in forum Programming
    Replies: 2
    Last Post: 10-21-2010, 11:07 PM
  5. using FindFirst with a Date Criteria (syntax error)
    By ajetrumpet in forum Programming
    Replies: 2
    Last Post: 09-10-2010, 11:01 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums