iglobalusa
Registered User.
- Local time
- Yesterday, 19:00
- Joined
- Jul 12, 2008
- Messages
- 30
I'm trying to edit fields in a recordset by looping through it using an ID number to match the record to edit. All records with a matching ID number are successfully edited except for the record prior to the last matching record. Can anyone help me resolve this problem?
Code:
Private Sub txtl_name_AfterUpdate()
On Error GoTo Error_txtl_name_AfterUpdate
'look for all records with the same stateno then update the same field
Dim strstateno As String
strstateno = Trim(Me.stateno)
strSQL = "Select * from labdata Where stateno = '" & strstateno & "'"
Set DAO_DB = CurrentDb
Set DAO_RS = DAO_DB.OpenRecordset(strSQL, dbOpenDynaset)
'prevent write conflict
If Me.Form.Dirty Then Dirty = False
With DAO_RS
'find the first stateno match to edit
.FindFirst "[stateno] = '" & strstateno & "'"
'search for stateno match in labdata
If Not DAO_RS.NoMatch Then
'edit l_name field
.Edit
!l_name = Me.l_name
!transfer = 0
'commit the edit
.Update
End If
Do While Not DAO_RS.EOF
'keep finding the next match until EOF
.FindNext "[stateno] = '" & strstateno & "'"
If Not DAO_RS.NoMatch Then
'edit l_name field
.Edit
!l_name = Me.l_name
!transfer = 0
'commit the edit
.Update
End If
'move to next record if not EOF
.MoveNext
Loop
End With
'close recordset
DAO_RS.Close
Set DAO_RS = Nothing
Exit_txtl_name_AfterUpdate:
Exit Sub
Error_txtl_name_AfterUpdate:
MsgBox "Error Number: " & Err.Number & vbCrLf & "Error Description: " & _
Err.Description, vbInformation, "Error:"
Resume Exit_txtl_name_AfterUpdate
End Sub