Hello friends,

If i want to edit one record,after clicking cmdEdit
I have to give the empno to find out that particular record.
After displaying the details,If I click movenext,it is not working.
I am getting an error "Either you are at the first record or the last record"
It is not moving to the next record.Please help me.




Code:
Public Sub Form_Load()


    Set Cn = New ADODB.Connection 
    Cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=" & App.Path & "\emp.mdb"
        Cn.Open
    Set rs = New ADODB.Recordset   
  rs.Open "emp", Cn, adOpenDynamic, adLockOptimistic, adCmdTable
        
      
fillfields 

Do While Not rs.EOF
               rs.MoveNext
       Loop

End Sub

Private Function Diplay_Custumers(qry As String)
On Error Resume Next
If rs.State > 0 Then rs.Close
rs.Open qry, conn, adOpenForwardOnly, adLockReadOnly
If rs.EOF = False Then
txtempno.Text = rs(0)
txtename.Text = rs(1)
txtdate.Text = rs(2)
txtpay.Text = rs(3)
txtamt.Text = rs(4)
txtremarks.Text = rs(5)
ElseIf rs.EOF = True And rs.BOF = True Then
             MsgBox "Badgeno does not exists"
             txtempno.Text = ""
             txtempno.SetFocus
             
             
End If

Private Sub cmdnext_Click(Index As Integer)

 If rs.EOF = True Then
MsgBox "End of File"
rs.MoveFirstElse
rs.MoveNext
End If
End Sub

Public Sub fillfields()
    If Not (rs.BOF = True Or rs.EOF = True) Then 
        txtempno.Text = rs.Fields("empno") 
    txtename.Text = rs.Fields("ename") 
 txtdate.Text = rs.Fields("date") 
 txtpay.Text = rs.Fields("payto")   
   txtamt.Text = rs.Fields("amt")  
txtremarks.Text = rs.Fields("remarks")    
          Else
           MsgBox "Either you are at the first record or the last record.", vbExclamation, "Cannot Move"
    End If

Private Sub cmdEdit_Click()
Call EnabledTrue
If cmdEdit.Caption = "&FIND" Then

   cmdEdit.Caption = "&UPDATE"
'cbocheqno.Visible = True

'txtcheqno.Visible = False

  cmdDelete.Enabled = False
       cmdnew.Enabled = False
        cmdcancel.Enabled = True
        cmdDelete.Enabled = True
               txtempno.SetFocus
       
        EnabledcmdTrue
         ElseIf cmdEdit.Caption = "&UPDATE" Then
    If Trim(txtcheqno.Text) = "" Then MsgBox "Please Enter the emp no.", vbInformation: Exit Sub
    
    Dim tmp_rs As New ADODB.Recordset
    Dim sql As String
    Dim searchcode As String
    searchcode = Trim(txtempno.Text)
   
    sql = "select * from emp where empno= " & searchcode
    tmp_rs.Open sql, conn, adOpenDynamic, adLockOptimistic
    
    If tmp_rs.EOF = False Then
    
     tmp_rs("empno") = txtempno.Text
     
     
     tmp_rs("ename_no") = txtename.Text
      tmp_rs("date") = txtdate.Text
      tmp_rs("payto") = txtpay.Text
      tmp_rs("amt") = txtamt.Text
      tmp_rs("remarks") = txtremarks.Text
 
       tmp_rs.Update
      MsgBox "Record Updated Successfully"
     
          Call clear
          
     tmp_rs.MoveNext
      cmdEdit.Caption = "&FIND"
      cmdnew.Enabled = True
      
       Else
        MsgBox "No records found", vbInformation
    End If
End If
'tmp_rs.Close

End Sub
End Sub