|
-
Nov 5th, 2002, 07:55 AM
#1
Thread Starter
Frenzied Member
***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:
Priavte Function List()
Dim Max As Long
conDB
Set oRs = New ADODB.Recordset
oRs.Open "PDetails", goCnn, dOpenKeyset, adLockOptimistic
Max = oRs.RecordCount
oRs.Move BOF
List1.Clear
For I = 1 To Max
List1.AddItem oRs!Name & "," & oRs("E-Mail")
oRs.MoveNext
Next I
End Funtion
VB Code:
Public Function conDB()
Set goCnn = New ADODB.Connection
goCnn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\DB5.mdb;"
goCnn.Open
End Function
Last edited by mxnmx; Nov 5th, 2002 at 01:04 PM.
-
Nov 5th, 2002, 08:13 AM
#2
VB Code:
Priavte Function List()
Dim Max As Long
conDB
Set oRs = New ADODB.Recordset
oRs.Open "PDetails", goCnn, dOpenKeyset, adLockReadOnly
oRs.MoveLast
Max = oRs.RecordCount
oRs.Move BOF
List1.Clear
For I = 1 To Max
List1.AddItem oRs!Name & "," & oRs("E-Mail")
oRs.MoveNext
Next I
End Funtion
try this instead
-
Nov 5th, 2002, 08:49 AM
#3
Thread Starter
Frenzied Member
It gives another error now:
Rowset does not support fetching backwards on this line
-
Nov 5th, 2002, 08:55 AM
#4
Frenzied Member
Instead of oRs.Move BOF, put
"If at first you don't succeed, then skydiving is not for you"
-
Nov 5th, 2002, 08:58 AM
#5
Thread Starter
Frenzied Member
Well I still get the same error: Rowset is not supported to fetch backwards on this line:
I'm now testing the code provided by kleinma
-
Nov 5th, 2002, 09:18 AM
#6
Frenzied Member
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"
-
Nov 5th, 2002, 09:35 AM
#7
Thread Starter
Frenzied Member
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???
-
Nov 5th, 2002, 09:45 AM
#8
Banned
Read this: http://www.vbforums.com/showthread.p...hreadid=205511
Perhaps it is what Peet says in that post....
-
Nov 5th, 2002, 12:08 PM
#9
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
-
Nov 5th, 2002, 01:02 PM
#10
Thread Starter
Frenzied Member
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!!!
-
Nov 5th, 2002, 01:03 PM
#11
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|