Results 1 to 3 of 3

Thread: [RESOLVED] Need help with ADODB

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2008
    Posts
    67

    Resolved [RESOLVED] Need help with ADODB

    As I have already stated that I need help with some simple problem I think? So what I have access file db and it reads and writes to it fine but when I want to go thought records with a Next Button I only move from first to second record and then it stops the code that I have is bellow and if you know what I am doing wrong please help.

    .bas File
    Public ac As New ADODB.Connection Public ar As New ADODB.Recordset Public CurrentForm As Form Public strConek, pword, CurrentUser As String Public rc, ctr, passFlag, liCtr, dbFlag, menuFlag, saveFlag As Integer Public Function dblink() Set ac = New ADODB.Connection Set ar = New ADODB.Recordset strConek = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\Data\Imenik.mdb;Persist " & _ "Security Info=False;Jet OLEDBatabase Password=cc03bn01" End Function
    Thanks!

    Next Button
    Private Sub cmdNext_Click() On Error GoTo Error_Handler Call dblink ar.Open "Select * From Data", strConek, adOpenStatic, adLockOptimistic If ar.EOF = False Then ar.MoveNext Call PopulateControls End If ar.Close Error_Handler: Select Case Err.Number Case 3021 MsgBox "Kraj Imenika End", , MSGTITLE End Select End Sub
    Last edited by BHCluster; Dec 8th, 2008 at 03:31 PM.

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Need help with ADODB

    Thread moved to Database Development forum (the "VB6" forum is meant for questions which don't fit in more specific forums)

    Your code is very hard to read - it seems you managed to remove the line breaks somehow!

    The problem is that you are opening a new recordset each time, which will always be at the first record (so doing a .MoveNext after will always leave you at the second record). Not only that, but because you haven't closed it from the previous time, you are potentially wasting memory, and are risking database corruption.

    I'd recommend seeing Beacons ADO Tutorial in our Database Development FAQs/Tutorials (at the top of this forum), as it covers how to do next/prev buttons and many other things.

    I would also recommend reading the article Why shouldn't I use "Dim .. As New .."? from our Classic VB FAQs (in the FAQ forum, which is shown near the top of our home page)

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Nov 2008
    Posts
    67

    Re: Need help with ADODB

    I see now where the problem was made thanks for the heads up and the answer that I found was from this link: http://www.vbforums.com/showthread.php?threadid=153935 as you have suggested!

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