Results 1 to 10 of 10

Thread: List type Combo Box population (resolved)

  1. #1

    Thread Starter
    Fanatic Member demotivater's Avatar
    Join Date
    Jun 2002
    Location
    is everything
    Posts
    627

    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.

  2. #2
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132
    There are few "work-arraounds": you may check for ListCount = 0 and simply ignore that combo ...

  3. #3
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758
    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).

  4. #4

    Thread Starter
    Fanatic Member demotivater's Avatar
    Join Date
    Jun 2002
    Location
    is everything
    Posts
    627
    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?

  5. #5
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132
    In that case simply use one of the following:

    If Not IsNull(rst!FLD) Then ...
    or
    If Not Trim(rst!FLD) = "" Then ...

  6. #6
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132
    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.

  7. #7

    Thread Starter
    Fanatic Member demotivater's Avatar
    Join Date
    Jun 2002
    Location
    is everything
    Posts
    627
    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.

  8. #8
    Fanatic Member ahara's Avatar
    Join Date
    Nov 2003
    Location
    Toronto
    Posts
    531
    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

  9. #9

    Thread Starter
    Fanatic Member demotivater's Avatar
    Join Date
    Jun 2002
    Location
    is everything
    Posts
    627
    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.

  10. #10
    Fanatic Member ahara's Avatar
    Join Date
    Nov 2003
    Location
    Toronto
    Posts
    531
    don't forget you can always do an AddItem like:

    VB Code:
    1. 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
  •  



Click Here to Expand Forum to Full Width