Results 1 to 24 of 24

Thread: who can help me? please !

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2002
    Posts
    40

    who can help me? please !

    about get next record.
    for example:

    Dim rs As Recordset
    Private Sub nextrecord_Click()

    strsql = "select username from regedit "
    Set rs = db.OpenRecordset(strsql)
    rs.Movenext
    txtFields.Text = rs.Fields(0).Value
    End Sub

  2. #2
    Lively Member
    Join Date
    May 2002
    Location
    Nigeria
    Posts
    66

    Next Record

    You can achieve this by binding you textfiled to a data source and data field.
    On click of the bottonand with rst.movenext you can get the next record apearing on your screen Try it taht way and get back to me

  3. #3

    Thread Starter
    Member
    Join Date
    Jun 2002
    Posts
    40
    but if I do it like your speaking.
    I must have a fixation's path. but I don't want to do like that.
    so .......

  4. #4
    Swatty
    Guest
    What about next record.

    You give an example , but what is it you want to achieve.

    I didn't see a question about it.

  5. #5
    Swatty
    Guest
    Maybe you can post the answer you got through the private message in here , so people can see which answers you did get.

  6. #6

    Thread Starter
    Member
    Join Date
    Jun 2002
    Posts
    40
    In the form load you should place
    [Highlight=VB]
    strsql = "select username from regedit "
    Set rs = db.OpenRecordset(strsql)
    ' in the nextrecord_click you can leave the rest but have to add a line
    If Not rs.EOF then /////////here,there is a mistake.message:no variable or with block variable
    rs.Movenext
    txtFields.Text = rs.Fields(0).Value
    Else
    txtFields.Text = "End of recordset

    End if
    ' maybe you can add an extra button previous record
    If Not rs.BOF then
    rs.Moveprevious
    txtFields.Text = rs.Fields(0).Value
    Else
    txtFields.Text = "Begin of recordset

    End if

  7. #7
    Swatty
    Guest
    For the trying , You have to dim the rs as recordset in the header of the form module.
    this also applies for the db
    didn't you get an error when loading the form.

    Try to post all the code you have till now.

    Where you dim your objects , where you fill them and where you use them.

  8. #8

    Thread Starter
    Member
    Join Date
    Jun 2002
    Posts
    40
    this is all code:
    Option Explicit
    Const DBName As String = "\db197.mdb"
    Dim strPath As String
    Dim db As Database
    Dim rsTitles As Recordset
    Dim strsql As String
    Dim blnview As Boolean
    Dim rs As Recordset
    Private Sub nextrecord_Click()
    If Not rs.EOF Then//////////////here,there is a mistake.message:no variable or with block variable.

    rs.MoveNext
    txtFields.Text = rs.Fields(0).Value
    End If
    End Sub

    Private Sub Form_Load()

    'change the path!
    strPath = App.Path
    'open the database
    Set db = OpenDatabase(strPath & DBName)
    'open the recordset
    Set rsTitles = db.OpenRecordset("regedit")
    'make the search
    strsql = "select username from regedit where not isnull(id) "
    Set rs = db.OpenRecordset(strsql)
    End Sub

  9. #9
    Swatty
    Guest
    Ill try to help you out.
    It is not so good to place all your variables in the header section though.
    VB Code:
    1. Option Explicit
    2. Const DBName As String = "\db197.mdb"
    3. Dim strPath As String
    4. Dim db As Database
    5. Dim rsTitles As Recordset
    6. Dim strsql As String
    7. Dim blnview As Boolean
    8. Dim rs As Recordset
    9. Private Sub nextrecord_Click() [COLOR=darkred]
    10.     If  (rs) Is Nothing  Then
    11.           msgBox "recordset is lost"
    12.     else[/COLOR]
    13.           If Not rs.EOF Then
    14.                 rs.MoveNext
    15.                 txtFields.Text = rs.Fields(0).Value
    16.            End If [COLOR=darkred]
    17.      end if[/COLOR]
    18. End Sub
    19.  
    20. Private Sub Form_Load()
    21.  
    22. 'change the path!
    23. strPath = App.Path
    24. 'open the database
    25. Set db = OpenDatabase(strPath & DBName)
    26. 'open the recordset
    27. Set rsTitles = db.OpenRecordset("regedit")
    28. 'make the search
    29. strsql = "select username from regedit where not isnull(id) "
    30. Set rs = db.OpenRecordset(strsql)
    31. End Sub
    if the recordset is lost, it could be (if your developing in access)
    that access clears the objects after exiting a sub or function.

    If so you have to use a static integer to count the times that were clicked on the button.


    Call if necesary

    edit : (rs) Is Nothing

  10. #10
    Frenzied Member oh1mie's Avatar
    Join Date
    Sep 2001
    Location
    Finland
    Posts
    1,043
    It works on me
    but you gettin trouble if you are on last record
    try correct nextrecord_Click
    VB Code:
    1. Option Explicit
    2.  
    3. Const DBName As String = "\db197.mdb"
    4.  
    5. Private strPath  As String
    6. Private db       As Database
    7. Private rsTitles As Recordset
    8. Private strsql   As String
    9. Private blnview  As Boolean
    10. Private rs       As Recordset
    11. Private Sub Form_Load()
    12.  
    13. 'change the path!
    14.    strPath = App.Path
    15. 'open the database
    16.    Set db = OpenDatabase(strPath & DBName)
    17. 'open the recordset
    18.    Set rsTitles = db.OpenRecordset("regedit")
    19. 'make the search
    20.    strsql = "select username from regedit where not isnull(id) "
    21.    Set rs = db.OpenRecordset(strsql)
    22.    
    23. End Sub
    24. Private Sub nextrecord_Click()
    25.  
    26.     If Not rs.EOF Then
    27.        rs.MoveNext
    28.     Else
    29.        rs.MovePrevious
    30.     End If
    31.     If Not rs.EOF Then txtFields.Text = rs.Fields(0).Value
    32.  
    33. End Sub
    oh1mie/Vic


  11. #11

    Thread Starter
    Member
    Join Date
    Jun 2002
    Posts
    40
    Private Sub nextrecord_Click()
    If (rs) Is Nothing Then ////////////here,there is a mistake yet.
    msgBox "recordset is lost"
    else
    If Not rs.EOF Then
    rs.MoveNext
    txtFields.Text = rs.Fields(0).Value
    End If
    end if
    End Sub

    I have an access database.

  12. #12
    Frenzied Member oh1mie's Avatar
    Join Date
    Sep 2001
    Location
    Finland
    Posts
    1,043
    VB Code:
    1. 'make the search
    2.    strsql = "select username from regedit where not isnull(id) "
    3.    Set rs = db.OpenRecordset(strsql)
    4.  
    5. End Sub  ' Break you code here and look with watch window, what is rs.
    oh1mie/Vic


  13. #13
    Swatty
    Guest
    Try to edit your form load event to this.

    VB Code:
    1. Private Sub Form_Load()
    2.  
    3. 'change the path!
    4.    strPath = App.Path
    5. 'open the database
    6.    Set db = OpenDatabase(strPath & DBName)
    7. 'open the recordset
    8.    Set rsTitles = db.OpenRecordset("regedit")
    9. 'make the search
    10.    strsql = "select username from regedit where not isnull(id) "
    11.    Set rs = db.OpenRecordset(strsql)
    12.    rs.MoveLast
    13.    rs.MoveFirst
    14.    MsgBox rs.RecordCount
    15. End Sub

  14. #14

    Thread Starter
    Member
    Join Date
    Jun 2002
    Posts
    40
    there is a picture about that question:
    Attached Images Attached Images  

  15. #15
    Swatty
    Guest
    Sorry man can't help you with that.

    I'll start next year in first grade of basic school.
    (six year old)

  16. #16

    Thread Starter
    Member
    Join Date
    Jun 2002
    Posts
    40
    Swatty
    Hyperactive Member

    Registered: Sep 00
    Location: Belgium
    Posts: 457
    Sorry man can't help you with that.

    I'll start next year in first grade of basic school.
    (six year old)


    __________________
    CU :-)
    Swatty

    I can't understand what's means??

  17. #17
    Swatty
    Guest
    I have tried it on my machine, working in access.

    All works fine.

    I can't understand what is on the jpg you've added in other reply.

    That was my reply.

  18. #18

    Thread Starter
    Member
    Join Date
    Jun 2002
    Posts
    40
    but it is really result like that picture.
    OS:win2000,
    software:VB6.

    why???

  19. #19
    Swatty
    Guest
    Did you try this ??


    VB Code:
    1. Private Sub Form_Load()
    2.  
    3. 'change the path!
    4.    strPath = App.Path
    5. 'open the database
    6.    Set db = OpenDatabase(strPath & DBName)
    7. 'open the recordset
    8.    Set rsTitles = db.OpenRecordset("regedit")
    9. 'make the search
    10.    strsql = "select username from regedit where not isnull(id) "
    11.    Set rs = db.OpenRecordset(strsql)
    12.    rs.MoveLast
    13.    rs.MoveFirst
    14.    MsgBox rs.RecordCount
    15. End Sub

  20. #20
    Frenzied Member oh1mie's Avatar
    Join Date
    Sep 2001
    Location
    Finland
    Posts
    1,043
    Check if you have somewhere else rs or db variable manipulation, what changes that connect what you open on form load.
    Your code is workking fine on my computer
    oh1mie/Vic


  21. #21
    ^:^...ANGEL...^:^ wrack's Avatar
    Join Date
    Mar 2002
    Location
    Melbourne, AUSTRALIA
    Posts
    2,695

    Thumbs up Try this...

    What about this...

    [Highlight=VB]

    Private Sub Form_Load()
    Dim rs As Recordset

    strsql = "select username from regedit "
    Set rs = db.OpenRecordset(strsql)
    End Sub

    Private Sub Display()
    txtFields.Text = rs!username
    End Sub

    Private Sub cmdNext_Click()
    If rs.RecordCount > 0 Then
    rs.MoveNext
    If Not rs.EOF Then
    Call Display
    Else
    rs.MoveLast
    MsgBox "End of File.", vbInformation
    Call Display
    End If
    End If
    End Sub
    [\vbcode]

    Hope this will help...

    Cheers...

  22. #22
    Lively Member Surgeon's Avatar
    Join Date
    Oct 2000
    Posts
    121

    Thumbs down

    flyflydream2002, I took a look at the picture you've sent.
    The problem is that in the picture there are 2 code lines that are commented (the 2 green code lines). And the error you get is because you do this :
    If Not Rs.EOF Then
    and there is NO rs variable initialized, because you commented this line :
    Set rs = ...

    Maybe this helped a little bit.

  23. #23
    ^:^...ANGEL...^:^ wrack's Avatar
    Join Date
    Mar 2002
    Location
    Melbourne, AUSTRALIA
    Posts
    2,695

    Thumbs up This will look better...

    What about this...

    VB Code:
    1. Private Sub Form_Load()
    2.     Dim rs As Recordset
    3.  
    4.     strsql = "select username from regedit "
    5.     Set rs = db.OpenRecordset(strsql)
    6. End Sub
    7.  
    8. Private Sub Display()
    9.     txtFields.Text = rs!username
    10. End Sub
    11.  
    12. Private Sub cmdNext_Click()  
    13.     If rs.RecordCount > 0 Then
    14.         rs.MoveNext
    15.         If Not rs.EOF Then
    16.             Call Display
    17.         Else
    18.             rs.MoveLast
    19.             MsgBox "End of File.", vbInformation
    20.             Call Display
    21.         End If
    22.     End If
    23. End Sub

    Hope this will help...

    Cheers...

  24. #24

    Thread Starter
    Member
    Join Date
    Jun 2002
    Posts
    40
    wrack:thank u
    thank you everyone.

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