Question:

What is the error in this code in VB6?

by  |  earlier

0 LIKES UnLike

it always say "no current record" when i get to the last record

Option Explicit

Dim DB As Database

Dim RS As Recordset

Private Sub Command4_Click()

End

End Sub

Private Sub cmdadd_Click()

cmdsave.Visible = True

cmdcancel.Visible = True

cmdadd.Visible = False

cmdprev.Visible = False

cmdnext.Visible = False

cmdexit.Visible = False

cmdfirst.Visible = False

cmdlast.Visible = False

Text1.Text = ""

Text2.Text = ""

Text3.Text = ""

End Sub

Private Sub cmdcancel_Click()

cmdsave.Visible = False

cmdcancel.Visible = False

cmdadd.Visible = True

cmdprev.Visible = True

cmdnext.Visible = True

cmdexit.Visible = True

cmdfirst.Visible = True

cmdlast.Visible = True

Set DB = OpenDatabase(App.Path & "/db1.mdb")

Set RS = DB.OpenRecordset("STUD_INFO")

Text1.Text = RS!Name

Text2.Text = RS!Course

Text3.Text = RS!address

End Sub

Private Sub cmdexit_Click()

End

End Sub

Private Sub cmdfirst_Click()

RS.MoveFirst

Text1.Text = RS!Name

Text2.Text = RS!Course

Text3.Text = RS!address

End Sub

Private Sub cmdlast_Click()

RS.MoveLast

Text1.Text = RS!Name

Text2.Text = RS!Course

Text3.Text = RS!address

End Sub

Private Sub cmdnext_Click()

RS.MoveNext

Text1.Text = RS!Name

Text2.Text = RS!Course

Text3.Text = RS!address

If RS.EOF = True Then

RS.MoveFirst

Text1.Text = RS!Name

Text2.Text = RS!Course

Text3.Text = RS!address

End If

End Sub

Private Sub cmdprev_Click()

RS.MovePrevious

Text1.Text = RS!Name

Text2.Text = RS!Course

Text3.Text = RS!address

If RS.BOF = True Then

RS.MoveLast

Text1.Text = RS!Name

Text2.Text = RS!Course

Text3.Text = RS!address

End If

End Sub

Private Sub cmdsave_Click()

Set DB = OpenDatabase(App.Path & "/db1.mdb")

Set RS = DB.OpenRecordset("STUD_INFO")

RS.AddNew

RS!Name = Text1.Text

RS!Course = Text2.Text

RS!address = Text3.Text

RS.Update

Text1.Text = ""

Text2.Text = ""

Text3.Text = ""

MsgBox "DATA SAVED", vbOKOnly, "app Message"

End Sub

Private Sub Form_Load()

cmdsave.Visible = False

cmdcancel.Visible = False

Set DB = OpenDatabase(App.Path & "/db1.mdb")

Set RS = DB.OpenRecordset("STUD_INFO")

Text1.Text = RS!Name

Text2.Text = RS!Course

Text3.Text = RS!address

End Sub

can someone fix it for me tnx

 Tags:

   Report

5 ANSWERS


  1. the code u just write means, "I have a problem with it, please help me"

    to fix it, we need a programmer to reply it. later~


  2. When moving through a recordset it would help if you were to check when at the end of record set, e.g., if rs.EOF then ....

  3. ............/´¯/)...........( \¯`\

    ............/....//........... ...\\....\

    .........../....//............ ....\\.... \

    ...../´¯/..../´¯\.........../¯ `\....\¯`\

    .././.../..../..../.|_......_| .\....\... .\...\.\..

    (.(....(....(..../.)..)..(..(. \....).... )....).)

    .\................\/.../....\. ..\/...... ........../

    ..\................. /........\................../

    ....\..............(.......... ..)....... ......./

    ......\.............\......... ../....... ....../  

  4. i think you need to add RS.MoveFirst after:

    Set RS = DB.OpenRecordset("STUD_INFO")

  5. I think it is better to change the coding of Private Sub cmdnext_Click() after you reach to if  RS.EOF = True Then  Add a msgbox "You can't go beyond." RS.MoveFirst and further coding need not be there. Same way please try with Private Sub cmdprev_Click() after reaching to First record. the coding after if RS.BOF = True Then msgbox "you can't go beyond this" RSMoveLast and further coding need not be there. ple try.

Question Stats

Latest activity: earlier.
This question has 5 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.
Unanswered Questions