-
April 20th, 2005, 11:22 AM
#1
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
-
April 20th, 2005, 11:47 AM
#2
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
-
April 20th, 2005, 12:02 PM
#3
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
-
April 20th, 2005, 01:20 PM
#4
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
-
April 20th, 2005, 04:03 PM
#5
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
-
April 20th, 2005, 05:00 PM
#6
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
-
April 20th, 2005, 08:16 PM
#7
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
-
April 20th, 2005, 08:32 PM
#8
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|