Results 1 to 4 of 4

Thread: very simple---->Next Record Problem

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Nov 2002
    Location
    Pakistan
    Posts
    28

    Unhappy very simple---->Next Record Problem

    HI


    I have a connection Mudule

    Public con As New ADODB.Connection
    Public rec As New ADODB.Recordset
    Sub main()
    On Error GoTo hell
    Set con = New ADODB.Connection
    Set rec = New ADODB.Recordset
    con.Open "Provider = Microsoft.Jet.Oledb.4.0; Data Source=" & App.Path & "\Revise.mdb"
    rec.Open "Select * from Revise", con, 2, 3
    rec.MoveFirst
    Call fill
    Form1.Show
    hell:
    If Err.Number <> 0 Then
    MsgBox "Connection problem" & vbCrLf & vbCrLf & Err.Description, vbCritical, "Ahan"
    End If
    End Sub
    Function fill()
    With rec
    Form1.txtroll.Text = .Fields(0)
    Form1.txtname.Text = .Fields(1)
    Form1.txtcrs.Text = .Fields(2)
    Form1.txtmark.Text = .Fields(3)
    End With
    End Function
    Function blank()
    Form1.txtroll.Text = ""
    Form1.txtname.Text = ""
    Form1.txtcrs.Text = ""
    Form1.txtmark.Text = ""
    End Function
    Function check()
    If Form1.txtroll.Text = "" Then
    MsgBox "Please enter RollNo", vbCritical
    Else
    If Form1.txtname.Text = "" Then
    MsgBox "Please enter Name", vbCritical
    Else
    If Form1.txtcrs.Text = "" Then
    MsgBox "Please enter Course Title", vbCritical
    Else
    If Form1.txtmark.Text = "" Then
    MsgBox "Please enter Marks", vbCritical
    End If
    End If
    End If
    End If
    End Function

    and the problem is with my next record

    plese can u provide me the code for next record with the message "u are already at last record"
    or
    correct this code

    Private Sub cmdnext_Click()
    On Error GoTo hell
    If rec.State = adStateOpen Then
    rec.Close
    End If
    rec.Open "select * from Revise", con, 2, 3
    rec.MoveNext
    Call fill
    hell:
    If Err.Number <> 0 Then
    MsgBox "Error in Syntax" & vbCrLf & vbCrLf & Err.Description, vbCritical, "Ahan"
    End If
    End Sub

    this code returns only one next record
    i hope u will help me
    i also attach my file

    Thanx in advance 4 help
    Attached Files Attached Files

  2. #2
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343
    Why haven't you used .Movenext property and .EOF property to check whether there are more records to move to??


    example:
    VB Code:
    1. if rst.eof then
    2.  msgbox "At last record"
    3. else
    4.  rst.movenext
    5. ' fill code..
    6. end if

    Vince

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  3. #3
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343
    Oh, and your validation could be changed ---- Use a booolean to say whether validation failed. And then its up to you whether you put pop ups in the code to tell the user.

    I am thinking along the lines of a user accidentally hitting return too early and then they get lots of error/validation msgs.


    Vince

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  4. #4
    Frenzied Member oh1mie's Avatar
    Join Date
    Sep 2001
    Location
    Finland
    Posts
    1,043
    I did fix a littlebit your code. Do not overwrite you original code
    Attached Files Attached Files
    oh1mie/Vic


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