[RESOLVED] Writing to ListView Problem
I am using VB6, ADO and Access 2002.
I am trying to write the first three fields from a Db to a listview;
Fields names are:
First_Name, Middle_Name, Surname.
Now the name may, or may not have a middle name, and I think this is what is causing me the problem :(
I am getting something wrong with the writing to the Listview, but I'm not sure why.
I am getting the error
Invalid property value
when the second item is to be added.
My Code:
vb Code:
Set rs = New ADODB.Recordset
Set cn = New ADODB.Connection
cn.ConnectionString = strConnection & App.Path & "\Membership.mdb"
cn.Open
strSQL = "SELECT First_Name, Middle_Name, Surname FROM tbl_Membership "
strSQL = strSQL & " WHERE First_Name <> '""'"
rs.Open strSQL, cn, adOpenForwardOnly, adLockReadOnly, adCmdText
i = 1
Do While Not rs.EOF
If rs!Middle_Name <> "" Then
If i = 1 Then
Set lvwItem = lvwMembers.ListItems.Add(, , rs!First_Name & " " & rs!Middle_Name & " " & rs!Surname)
Else
lvwItem.SubItems(i) = rs!First_Name & " " & rs!Middle_Name & " " & rs!Surname
End If
Else
If i = 1 Then
Set lvwItem = lvwMembers.ListItems.Add(, , rs!First_Name & " " & rs!Surname)
Else
lvwItem.SubItems(i) = rs!First_Name & " " & rs!Surname
End If
End If
i = i + 1
rs.MoveNext
Loop
Set rs = Nothing
cn.Close
Set cn = Nothing
Re: Writing to ListView Problem
I'm not getting what you are doing?
What is going on with the i variable? Why not just loop through the recordset and load what is there? If there is no middle name, nothing will be in the column.
Re: Writing to ListView Problem
:confused: Are you trying to add all three fields into one column?
Re: Writing to ListView Problem
Quote:
Originally Posted by Hack
:confused: Are you trying to add all three fields into one column?
Yes, because I don't want a gap in the middle column if there is no middle name.
I am trying to populate a listview with all members names from a database.
Then, when the user selects one of the names, the complete record for this member is added into an array of textboxes.
Also, I would like to have a second column (hidden) with the Primary key in it to know which record to show.
Is this the best way to do this?
Re: Writing to ListView Problem
I would have three columns. One for the first name, one for the middle name, and one for the last name.
Just click on the desired column, scoop all three up and run your query.
Re: Writing to ListView Problem
Quote:
Originally Posted by Hack
I would have three columns. One for the first name, one for the middle name, and one for the last name.
Just click on the desired column, scoop all three up and run your query.
So you wouldn't worry about there being an empty column then?
Again, If I wanted to add a fourth column for the ID of the record, to make it hidden, is this done at runtime, or am I missing one of the properties?
Re: Writing to ListView Problem
If there is an empty column in your ListView it will be because there is an empty field in your database.
You can add the column in design. Just set its width to 0
Re: Writing to ListView Problem
Quote:
Originally Posted by Hack
You can add the column in design. Just set its width to 0
Just done this ;)
I'm just not sure what the proper standards are.
This project is not just for me to use, so I want it to look right, and the way people expect it to look, if you know what I mean. :)
Re: Writing to ListView Problem
If you don't separate them, chances are you might have to parse the darn string just to get the names into three variables (I have no idea why, but it seems everytime I try to do something like this, that always happens.)
Plus, I think it would look much better with three separate columns.
Re: Writing to ListView Problem
Quote:
Originally Posted by Hack
If you don't separate them, chances are you might have to parse the darn string just to get the names into three variables (I have no idea why, but it seems everytime I try to do something like this, that always happens.)
Hmm, I was actually looking at this when you first replied to the thread :LOL:
Quote:
Originally Posted by Hack
Plus, I think it would look much better with three separate columns.
This is the sort of thing you know, as a professional programmer, but I have to guess at. I'm never really happy with my designs, but I guess that comes in time :rolleyes:
Re: [RESOLVED] Writing to ListView Problem
Quote:
Originally Posted by aikidokid
Hmm, I was actually looking at this when you first replied to the thread :LOL:
Actually, with only three items it would be fairly easy to do using Split.