How to set blank spaces in combobox for Access 2003 and VBA

48 views Asked by At

I need to display a combobox with several values by code. Some of those values define a "section", and the items after that are "details". I want the details to be displayed a bit on the right. But when adding the items to the combobox, it seems like it trims. I want to display this when the combo expands:

Fruits
  Orange
  Apple
  Melon
Drinks 
  Coffee
  Milk
  Water

But the System displays this:

Fruits
Orange
Apple
Melon
Drinks 
Coffee
Milk
Water

Any ideas on the Add function to add items by cose in Access 2003? Thanks

2

There are 2 answers

2
Gustav On

Build a rowsource (value list) that includes the spaces:

"Fruits";"  Orange";"  Apple";"  Melon";"Drinks ";"  Coffee";"  Milk";"  Water"

Output:

enter image description here

0
Shahram Alemzadeh On

As a complementary to Gustav's answer:

To disable selecting section-name itself, use the change event to detect whether its first character is not blank:

SUB COMBOBOX_CHANGE
    IF COMBOBOX.VALUE LIKE " *" THEN ' item - valid to select
        COMBOBOX.VALUE=TRIM(COMBOBOX.VALUE)
    ELSE ' section - invalid to select
        COMBOBOX.VALUE=""
        COMBOBOX.DROPDOWN
    ENDIF
END SUB