|
-
Jan 11th, 2002, 04:03 PM
#1
Thread Starter
Frenzied Member
Problem with ListView
Hello Everyone
I'm trying to use ListView to get contents of an Access Table into it...And I use the following code to do so...but while executing the statements I get an error- Invalid property Value
Please help!!!!
Dim Db As Database
Dim Rs As Recordset
Dim SQL As String
Dim MyItem As ListItem
Private Sub Form_Load()
Set Db = OpenDatabase("d:\check\taws\data.mdb")
SQL = "SELECT * FROM Audit "
Set Rs = Db.OpenRecordset(SQL, dbOpenDynaset)
Do While Not Rs.EOF
Set MyItem = ListView1.ListItems.Add(, , Rs(0))
MyItem.SubItems(1) = Rs(0)
MyItem.SubItems(2) = Rs(1)
'continue as above until all fields are accounted for
Rs.MoveNext
Loop
Rs.Close
End Sub
-
Jan 11th, 2002, 06:34 PM
#2
How many columns does your listview have?
This code:
Code:
Set MyItem = ListView1.ListItems.Add(, , Rs(0))
MyItem.SubItems(1) = Rs(0)
MyItem.SubItems(2) = Rs(1)
Is kind of interesting since it has you adding Rs(0) for the text of the listview (column 1) then putting it in column 2 as well with MyItem.SubItems(1) = Rs(0).
Are you intending to put the same database value in both columns 1 and 2?
Normally when I add an item to a listview I do so like this:
Code:
Set MyItem = ListView1.ListItems.Add
With MyItem
.Text = Rs(0) ' Column 1 value.
.SubItems(1) = Rs(0) ' Column 2 value.
.SubItems(2) = Rs(1) ' Column 3 value.
End With
...which is basically the same thing you had, just a little easier to follow for me.
Anyways...I don't know if this helps...to really help it'd be good to know exactly where your code breaks when you get the error.
Cheers,
Paul
-
Jan 11th, 2002, 07:26 PM
#3
Thread Starter
Frenzied Member
Yo!
I tried your code but it gave me the same problem I have pasted the line where it breaks and gives me an error...
MyItem.SubItems(1) = Rs(0)
When I put my curson for SubItems(1), it reads: Invalid property value....
Any ideaS?
-
Jan 11th, 2002, 07:32 PM
#4
-
Jan 11th, 2002, 07:35 PM
#5
Need-a-life Member
Sth like this.... but I didn't try it:
VB Code:
Dim Db As Database
Dim Rs As Recordset
Dim SQL As String
Dim MyItem As ListItem
Private Sub Form_Load()
Set Db = OpenDatabase("d:\check\taws\data.mdb")
SQL = "SELECT * FROM Audit "
Set Rs = Db.OpenRecordset(SQL, dbOpenDynaset)
Do While Not Rs.EOF
Set MyItem = ListView1.ListItems.Add(, , Rs(0))
MyItem.SubItems.add , "FirstColumn", Rs.Fields(0)
MyItem.SubItems.add , "SecondColumn", Rs.Fields(1)
'continue as above until all fields are accounted for
Rs.MoveNext
Loop
Rs.Close
End Sub
Emiliano F. Martín
If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
Encourage the person who helped you to keep doing it, and give him the points he deserves.
MP3 Organizer: Freeware to logically organize all your MP3s.
-
Jan 11th, 2002, 07:35 PM
#6
mxnmx: Why did you post the same question twice under a different title?
-
Jan 11th, 2002, 07:40 PM
#7
Thread Starter
Frenzied Member
Around two hours ago, I think there was a problem with this site....It was giving me an error that thread not posted...while it was posted....
-
Jan 11th, 2002, 07:44 PM
#8
Thread Starter
Frenzied Member
I tried this code, Mc Brain...but got an error.
MyItem.SubItems.Add , "FirstColumn", Rs.Fields(0)
It gave an error while highlighting the word Add: Argument not optional
-
Jan 11th, 2002, 07:55 PM
#9
Is now...
VB Code:
Set MyItem = ListView1.ListItems.Add(, , Rs0)) 'rs 0
MyItem.SubItems(1) = Rs(0) ' rs 0
MyItem.SubItems(2) = Rs(1)
'should be
Set MyItem = ListView1.ListItems.Add(, , Rs(0)) rs 0
MyItem.SubItems(1) = Rs(0) rs 1
MyItem.SubItems(2) = Rs(1) rs 2
'etc
-
Jan 11th, 2002, 07:57 PM
#10
-
Jan 11th, 2002, 07:59 PM
#11
Thread Starter
Frenzied Member
Hack, it still gives the same error with the code that you made changes to...Mc Brain code works with ListSubItems but it doesn't display anything...at all in the List view...
-
Jan 11th, 2002, 08:03 PM
#12
Thread Starter
Frenzied Member
With the following code, I don't get any error executing it, but it does not display anything in the ListView....
Dim Db As Database
Dim Rs As Recordset
Dim SQL As String
Dim MyItem As ListItem
Private Sub Form_Load()
Me.WindowState = vbMaximized
Set Db = OpenDatabase("c:\test.mdb")
SQL = "SELECT * FROM Details "
Set Rs = Db.OpenRecordset(SQL, dbOpenDynaset)
Do While Not Rs.EOF
Set MyItem = ListView1.ListItems.Add(, , Rs(0))
MyItem.ListSubItems.Add , "FirstColumn", Rs.Fields(0)
MyItem.ListSubItems.Add , "SecondColumn", Rs.Fields(1)
'continue as above until all fields are accounted for
Rs.MoveNext
Loop
Rs.Close
End Sub
-
Jan 11th, 2002, 08:03 PM
#13
-
Jan 11th, 2002, 08:20 PM
#14
You would need the ListView setup in Report mode (as stated above) and need 3 columns.
Code:
With ListView1
.View = lvwReport
.FullRowSelect = True
.ColumnHeaders.Add , , "Column 1", 1440
.ColumnHeaders.Add , , "Column 2", 1440
.ColumnHeaders.Add , , "Column 3", 1440
End With
All of which can be done by right-clicking on the listview and selecting properties.
Paul
-
Jan 11th, 2002, 08:28 PM
#15
-
Jan 11th, 2002, 08:32 PM
#16
Thread Starter
Frenzied Member
Ok, it works...Thanks people...Now is there a way to make it look a bit better or atleast...This is the first time I have used a ListView....
-
Jan 11th, 2002, 08:35 PM
#17
-
Jan 11th, 2002, 08:43 PM
#18
Thread Starter
Frenzied Member
You know with some lines separating each column and rows...is it possible???
-
Jan 11th, 2002, 08:46 PM
#19
-
Jan 11th, 2002, 08:47 PM
#20
Right-click on your listview control and select 'properties' - there are lots of things you can do to its appearance. You can use the properties through code too but it's usually easier to experiment using the "right-click" properties.
Paul
-
Jan 11th, 2002, 08:56 PM
#21
Thread Starter
Frenzied Member
Thanks everyone!!!! We have finally made it work and change its appearance...;-)
-
Jan 12th, 2002, 03:25 PM
#22
So is it doing what you need/want it to do?
-
Jan 12th, 2002, 03:29 PM
#23
Thread Starter
Frenzied Member
Yea Hack, its working all thanks to you....and others who helped...I just need to create a query now that can search for records in three tables at the same time....I have posted a thread but haven't got any answer yet...could you help????
-
Jan 12th, 2002, 03:34 PM
#24
Originally posted by mxnmx
I just need to create a query now that can search for records in three tables at the same time
That sounds like a pretty straight forward SQL statement with a couple of JOINs. Should be no problem. I haven't seen the new thread that you created specifically for this, but I will take a look.
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
|