|
-
May 30th, 2007, 12:22 PM
#1
Thread Starter
Frenzied Member
[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
-
May 30th, 2007, 12:43 PM
#2
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.
-
May 30th, 2007, 12:45 PM
#3
Re: Writing to ListView Problem
Are you trying to add all three fields into one column?
-
May 30th, 2007, 12:48 PM
#4
Thread Starter
Frenzied Member
Re: Writing to ListView Problem
 Originally Posted by Hack
 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?
Last edited by aikidokid; May 30th, 2007 at 12:53 PM.
-
May 30th, 2007, 12:57 PM
#5
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.
-
May 30th, 2007, 01:00 PM
#6
Thread Starter
Frenzied Member
Re: Writing to ListView Problem
 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?
-
May 30th, 2007, 01:04 PM
#7
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
-
May 30th, 2007, 01:07 PM
#8
Thread Starter
Frenzied Member
Re: Writing to ListView Problem
 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.
-
May 30th, 2007, 01:10 PM
#9
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.
-
May 30th, 2007, 01:15 PM
#10
Thread Starter
Frenzied Member
Re: Writing to ListView Problem
 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:
 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
-
May 30th, 2007, 01:34 PM
#11
Re: [RESOLVED] Writing to ListView Problem
 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.
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
|