|
-
May 21st, 2004, 02:27 PM
#1
Thread Starter
Fanatic Member
List type Combo Box population (resolved)
I've got a function that populates a form from database records. On this form are several dropdown list comboboxes so the user can't type anything into them at data entry. When I fill this form, if there's no data in one of the combo box fields, I get an error that the text property is read only. I'm basically setting the combo box text to "" if there's no data. What's a work around for this error - I'm tempted to use resume next but don't really want to do that.
Last edited by demotivater; May 21st, 2004 at 03:12 PM.
-
May 21st, 2004, 02:42 PM
#2
There are few "work-arraounds": you may check for ListCount = 0 and simply ignore that combo ...
-
May 21st, 2004, 02:43 PM
#3
If there are no items in the list the Text property should be "" already. The is no need to set it manually.
Otherwise, use ListIndex = -1 to clear the selected item (and the Text property).
-
May 21st, 2004, 02:48 PM
#4
Thread Starter
Fanatic Member
I wasn't clear enough in the question. I'm reading data from a database and feeding the form. If the db field is empty, I set the combo box to "", thats when I'm getting the error. I guess I'll have to rework my function, it basically checks the db fields and populates the controls on the form with either the value in the field, or if it's null, it populates with "", theres combo boxes and text boxes on the form. So, I guess I gotta say if the field is null, then don't touch the combo box?
-
May 21st, 2004, 02:50 PM
#5
In that case simply use one of the following:
If Not IsNull(rst!FLD) Then ...
or
If Not Trim(rst!FLD) = "" Then ...
-
May 21st, 2004, 02:52 PM
#6
Although, setting "text" to a dropdown list doesn't make any sence - you add all values you have and then set ListIndex = 0 (first item) or whatever index you need.
-
May 21st, 2004, 02:55 PM
#7
Thread Starter
Fanatic Member
I just switched to the drop down list type becuase my users kept typing values into the regular combo box, so I'm not up to speed with this type of combo (obviously). List Index 0 would be the first item in the list, but what if I want it to display as blank - ie: they haven't stored anything from the available list yet.
-
May 21st, 2004, 02:57 PM
#8
Fanatic Member
Originally posted by demotivater
I wasn't clear enough in the question. I'm reading data from a database and feeding the form. If the db field is empty, I set the combo box to "", thats when I'm getting the error. I guess I'll have to rework my function, it basically checks the db fields and populates the controls on the form with either the value in the field, or if it's null, it populates with "", theres combo boxes and text boxes on the form. So, I guess I gotta say if the field is null, then don't touch the combo box?
I am a bit confused as to how you are setting the values of the combo's when there is data....you must be using .AddItem and then selecting an index....I mean you will always get the error you are getting if you try to set the .Text property as it is read only with the way you are using your combo. So I guess you could add a blank item if there is no data. But then again, if there is no data, why touch it at all? (as previously noted)
"Knowledge is gained when different people look at the same information in different ways"
- Louis Pasteur
-
May 21st, 2004, 03:02 PM
#9
Thread Starter
Fanatic Member
Yea, I'm just backwards on this control, just switched to it an hour ago and was trying to not have to rewrite a bunch of code. I fill the combo box with available values using add item, then I was setting the text property to the field value in the database, or "" if the value was null. So, I see I can't do this now with this type of combo. I'll just have to change a lot of code to "skip" the combo box if the db field value is null.
Thanks for the replies.
-
May 21st, 2004, 03:13 PM
#10
Fanatic Member
don't forget you can always do an AddItem like:
VB Code:
Combo1.AddItem "" & rs.Fields(0).Value
If the db field is null, you will still get a zero length string from the concatenation. Just a thought.
"Knowledge is gained when different people look at the same information in different ways"
- Louis Pasteur
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
|