Results 1 to 6 of 6

Thread: error in my code

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 2006
    Posts
    169

    error in my code

    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

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: error in my code

    There is a lot of recordset code here.

    Which line is blowing up?

  3. #3

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Jul 2006
    Posts
    169

    Re: error in my code

    Thanks for ur replies.I am getting an error In the line,

    Private Sub cmdnext_Click(Index As Integer)

    If rs.EOF = True Then
    MsgBox "End of File"
    rs.MoveFirst
    Else
    rs.MoveNextEnd If
    End Sub

  5. #5
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: error in my code

    i might be missing something here, but in cmdedit you are doing a query where empno = seachcode, so the recordset is presumably only returning 1 record, so no next record to move to
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  6. #6
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: error in my code

    Quote Originally Posted by Akshaya
    Thanks for ur replies.I am getting an error In the line,

    Private Sub cmdnext_Click(Index As Integer)

    If rs.EOF = True Then
    MsgBox "End of File"
    rs.MoveFirst
    Else
    rs.MoveNextEnd If
    End Sub
    What error are you getting and when does it happen? The first time you click the button?

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