|
-
Dec 4th, 2007, 02:04 AM
#1
Thread Starter
Addicted Member
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
-
Dec 4th, 2007, 12:59 PM
#2
Re: error in my code
There is a lot of recordset code here.
Which line is blowing up?
-
Dec 4th, 2007, 01:12 PM
#3
Re: error in my code
The first thing you should do is to remove the On Error Resume Next line and see what happens since that line may be masking errors.
-
Dec 9th, 2007, 02:38 AM
#4
Thread Starter
Addicted Member
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
-
Dec 9th, 2007, 04:45 AM
#5
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
-
Dec 9th, 2007, 10:57 AM
#6
Re: error in my code
 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|