Results 1 to 11 of 11

Thread: ***RESOLVED***Populating a ListBox (SIMPLE)

  1. #1

    Thread Starter
    Frenzied Member mxnmx's Avatar
    Join Date
    Dec 2001
    Location
    I'm back...now!!!
    Posts
    1,396

    ***RESOLVED***Populating a ListBox (SIMPLE)

    I'm using the following code to Populate a ListBox, but when I call this function List on a Command Button's click event, it does not populate the ListBox & during run time I checked the value of Recordcount it shows -1. I have a Access Database which has 4 tables that I'm trying to access...Any suggestions!!!

    VB Code:
    1. Priavte Function List()
    2. Dim Max As Long
    3. conDB
    4. Set oRs = New ADODB.Recordset
    5. oRs.Open "PDetails", goCnn, dOpenKeyset, adLockOptimistic
    6. Max = oRs.RecordCount
    7. oRs.Move BOF
    8. List1.Clear
    9.  
    10. For I = 1 To Max
    11. List1.AddItem oRs!Name & "," & oRs("E-Mail")
    12.     oRs.MoveNext
    13. Next I
    14. End Funtion

    VB Code:
    1. Public Function conDB()
    2.     Set goCnn = New ADODB.Connection
    3.     goCnn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\DB5.mdb;"
    4.     goCnn.Open
    5. End Function
    Last edited by mxnmx; Nov 5th, 2002 at 01:04 PM.
    Can't Remember Birthdays or Important Dates- Never Miss any Important Date(s)

  2. #2
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    VB Code:
    1. Priavte Function List()
    2. Dim Max As Long
    3. conDB
    4. Set oRs = New ADODB.Recordset
    5. oRs.Open "PDetails", goCnn, dOpenKeyset, adLockReadOnly
    6. oRs.MoveLast
    7. Max = oRs.RecordCount
    8. oRs.Move BOF
    9. List1.Clear
    10.  
    11. For I = 1 To Max
    12. List1.AddItem oRs!Name & "," & oRs("E-Mail")
    13.     oRs.MoveNext
    14. Next I
    15. End Funtion

    try this instead

  3. #3

    Thread Starter
    Frenzied Member mxnmx's Avatar
    Join Date
    Dec 2001
    Location
    I'm back...now!!!
    Posts
    1,396
    It gives another error now:
    Rowset does not support fetching backwards on this line
    VB Code:
    1. oRs.MoveLast
    Can't Remember Birthdays or Important Dates- Never Miss any Important Date(s)

  4. #4
    Frenzied Member Mega_Man's Avatar
    Join Date
    Mar 2001
    Location
    North of England, South-East of Iceland
    Posts
    1,067
    Instead of oRs.Move BOF, put
    VB Code:
    1. oRs.MoveFirst
    "If at first you don't succeed, then skydiving is not for you"

  5. #5

    Thread Starter
    Frenzied Member mxnmx's Avatar
    Join Date
    Dec 2001
    Location
    I'm back...now!!!
    Posts
    1,396
    Well I still get the same error: Rowset is not supported to fetch backwards on this line:

    VB Code:
    1. oRs.MoveLast

    I'm now testing the code provided by kleinma
    Can't Remember Birthdays or Important Dates- Never Miss any Important Date(s)

  6. #6
    Frenzied Member Mega_Man's Avatar
    Join Date
    Mar 2001
    Location
    North of England, South-East of Iceland
    Posts
    1,067
    Originally posted by mxnmx
    I'm now testing the code provided by kleinma
    Sorry, I thought that was the code you were having the problem with.
    Kleinma's will probably work. He's never usually wrong
    "If at first you don't succeed, then skydiving is not for you"

  7. #7

    Thread Starter
    Frenzied Member mxnmx's Avatar
    Join Date
    Dec 2001
    Location
    I'm back...now!!!
    Posts
    1,396
    Kleinma's will probably work. He's never usually wrong
    Yea his answers always work, but this time it is giving an error as posted above. The oly problem that I have is that RecordCount value is going to -1...its supposed to be positive & once it is positive it will populate the listbox. Any other ideas???
    Can't Remember Birthdays or Important Dates- Never Miss any Important Date(s)

  8. #8
    Banned Michael_Kamen's Avatar
    Join Date
    May 2001
    Location
    The Netherlands
    Posts
    1,180
    Read this: http://www.vbforums.com/showthread.p...hreadid=205511
    Perhaps it is what Peet says in that post....

  9. #9
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    Originally posted by mxnmx
    Yea his answers always work, but this time it is giving an error as posted above. The oly problem that I have is that RecordCount value is going to -1...its supposed to be positive & once it is positive it will populate the listbox. Any other ideas???
    did u copy my code exactly?? or did you just add in the line about moving last?? because if you notice i changed the lock type as well... to adLockReadOnly which should allow for forwards and backwards fetching... let me know.. and if it still doesn't work i will look into another solution... BTW what version of ADO are you referencing (if what i said doesn't work)


    don't be fooled by my answers that seem to make sence...and I am wrong plenty

  10. #10

    Thread Starter
    Frenzied Member mxnmx's Avatar
    Join Date
    Dec 2001
    Location
    I'm back...now!!!
    Posts
    1,396
    Originally posted by kleinma
    adLockReadOnly which should allow for forwards and backwards fetching.
    It works now, the lock type was the problem...I have now changed it thanks!!!
    Can't Remember Birthdays or Important Dates- Never Miss any Important Date(s)

  11. #11
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    ok so i was right on this one

    glad to hear it is working for ya

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