CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Dec 2002
    Posts
    55

    I need to set CurrentRecord in a DAO recordset...

    I'm using the FindFirst method to find the matching record in a field but it will only update the first record. What am I doing wrong?

    Code:
    With rstLoggedIn
        .MoveFirst
        Do Until .EOF - 1
        .FindFirst !employeeid = EmpID
        .MoveNext
        If .NoMatch Then
            MsgBox "No records found with " & _
            EmpID & "."
            Exit Do
        End If
        Loop
        .Edit
        !EquipSetF1 = cboEquipSetF1.Text
        !EquipSetF2 = cboEquipSetF2.Text
        !LoggedIn = True
        .Update
    End With
    Thanks
    Rel

  2. #2
    Join Date
    Aug 2003
    Location
    Sydney, Australia
    Posts
    1,900

    Re: I need to set CurrentRecord in a DAO recordset...

    You are continually saying FINDFIRST

    ie, always find the first occurance of the match in your loop

    If you want subsequent occurances of the same match you will need to say

    FINDNEXT to find those records AFTER the first found record

  3. #3
    Join Date
    Dec 2002
    Posts
    55

    Re: I need to set CurrentRecord in a DAO recordset...

    I am looking for the first occurance of the string EmpID in the EmployeeID field. There is only one occurance of a particular EmpID in this recordset. The NoMatch remains false, meaning the record was found. However, when I try to Edit the found record, it only changes the first record. I tried FindNext with the same results.

    Thanks
    Rel

  4. #4
    Join Date
    Aug 2003
    Location
    Sydney, Australia
    Posts
    1,900

    Re: I need to set CurrentRecord in a DAO recordset...

    Take out your .MOVENEXT statement

    Also .MOVEFIRST is not required


    Code:
    With rstLoggedIn
         Do Until .EOF - 1
        .FindFirst !employeeid = EmpID
        If .NoMatch Then
            MsgBox "No records found with " & _
            EmpID & "."
            Exit Do
        End If
        Loop
        .Edit
        !EquipSetF1 = cboEquipSetF1.Text
        !EquipSetF2 = cboEquipSetF2.Text
        !LoggedIn = True
        .Update
    End With

  5. #5
    Join Date
    Sep 2001
    Location
    Québec, Canada
    Posts
    1,923

    Re: I need to set CurrentRecord in a DAO recordset...

    Remove this loop, if there is no match found, it will loop forever, you only need ONE .findfirst call, then the recordset will try to find the first occurance, browsing all the records, you don't need to try another findfirst on this recordset, so no need for a loop. I guess this should work correctly:

    Code:
    With rstLoggedIn
    
        .FindFirst !employeeid = EmpID
    
        If .NoMatch Then
            MsgBox "No records found with " & _
            EmpID & "."
        Else
           .Edit
            !EquipSetF1 = cboEquipSetF1.Text
            !EquipSetF2 = cboEquipSetF2.Text
            !LoggedIn = True
            .Update
        End If
    
    End With
    JeffB
    CodeGuru VB FAQ Visual Basic Frequently Asked Questions
    VB Code color Tool to color your VB code on CodeGuru
    Before you post Importants informations to know before posting

  6. #6
    Join Date
    Dec 2002
    Posts
    55

    Re: I need to set CurrentRecord in a DAO recordset...

    OK, Still no luck. It will only edit and update the first record. EmpID is correct and it DOES exist in the table... In fact I read the EmployeeID field to populate a combobox, Which I use to select EmpID. When I select the second records EmployeeID and try to FindFirst, NoMatch goes true.

    Code:
    Private Sub cmdLogIn_Click()
    
    Set rstLoggedIn = dbPageMe.OpenRecordset("LoggedIn", dbOpenDynaset)
    
    If cboEquipSetF1.Text = "" And cboEquipSetF2.Text = "" Then
        MsgBox "Please Select Equipment Set"
        Exit Sub
    End If
    
    With rstLoggedIn
    
        .FindFirst !EmployeeID = EmpID
    
        If .NoMatch Then
            MsgBox "No records found with " & EmpID & "."
        Else
            .Edit
            !EquipSetF1 = cboEquipSetF1.Text
            !EquipSetF2 = cboEquipSetF2.Text
            !LoggedIn = True
            .Update
        End If
    
    End With
    
    rstLoggedIn.Close
    
    Me.Hide
    
    End Sub
    Thanks
    Rel

  7. #7
    Join Date
    Sep 2001
    Location
    Québec, Canada
    Posts
    1,923

    Re: I need to set CurrentRecord in a DAO recordset...

    The .FindFirst() method ask for a string parameters, you are not using it correctly, what you need to do is something like that:

    .FindFirst "EmployeeID = " & EmpID

    It's like using an SQL where clause.

    JeffB
    CodeGuru VB FAQ Visual Basic Frequently Asked Questions
    VB Code color Tool to color your VB code on CodeGuru
    Before you post Importants informations to know before posting

  8. #8
    Join Date
    Dec 2002
    Posts
    55

    Re: I need to set CurrentRecord in a DAO recordset...

    Yes you are correct sir. this did it

    Code:
    With rstLoggedIn
        .FindFirst "EmployeeID = '" & EmpID & "'"
        .Edit
        !EquipSetF1 = cboEquipSetF1.Text
        !EquipSetF2 = cboEquipSetF2.Text
        !LoggedIn = True
        .Update
    End With

    Many thanks... again, Jeff
    Relentless

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured