Problem with the format property of a combo box. (1 Viewer)

AHeyne

Registered User.
Local time
Today, 05:15
Joined
Jan 27, 2006
Messages
280
My goal is to display gray text in a combo box that does not contain a value (null), indicating that the user should select a value from the list. Once a value has been selected, it should be displayed in black text.

This works fine in a combo box with a single column of type Text (see attached sample database).

Now I would like to implement this behavior for a combo box that contains two columns, a hidden bound numeric value column and a text column to be displayed.

However, this does not work. I have already tried various combinations of column order and format property values. Nothing works.

Does anyone have a solution for this?
 

Attachments

To get the formatting you want, you must have the default text specified in the bound column.
So either
1. Change the column widths to e.g. 2cm;2cm and modify the format spec
Or
2. change the bound column to 2

1762330605986.png

However doing the latter will generate a new issue for you to deal with....
 
Last edited:
you can add 2 dummy textbox in front of those comboboxes.
 

Attachments

There's not much formatting I have been able to do with combo box controls, other than change background colors. I tried using conditional formatting to change font color from black to gray for discontinued values which users cannot select, but need to remain in the source table for historical purposes. Instead, I had to display a 2nd column with an X to indicate the value is discontinued.

I also wanted to display placeholder labels inside combo and textbox controls, like commonly done in web forms. That would significantly provide more space on forms, versus displaying labels next to controls.
 
Last edited:
To get the formatting you want, you must have the default text specified in the bound column.
So either
1. Change the column widths to e.g. 2cm;2cm and modify the format spec
Or
2. change the bound column to 2

However doing the latter will generate a new issue for you to deal with....
- Using suggestion 1 results in having the first number column and not the text column beiing displayed after selecting a value.
- Usind suggestion 2, as you already mentioned, has the disadvantage that I can no more read out the value property but have to read `uxMultiColumnSample.Column(0)` instead. But that would be bearable if there were no other option.
 
There's not much formatting I have been able to do with combo box controls, other than change background colors. I tried using conditional formatting to change font color from black to gray for discontinued values which users cannot select, but need to remain in the source table for historical purposes. Instead, I had to display a 2nd column with an X to indicate the value is discontinued.

I also wanted to display placeholder labels inside combo and textbox controls, like commonly done in web forms.
I do something similar, but I also show all inactive elements appear at the end, after all the active ones.
 
I do something similar, but I also show all inactive elements appear at the end, after all the active ones.
I added a custom SortOrder field to the lookup table to place inactives at end, and most frequently selected values at the top.
 
Last edited:
Another option (but more work) is to create a bespoke combo using a textbox and a continuous form that looks like the dropdown. Has other benefits such as being able to use colour and/or richtext in the dropdown
 
Another option (but more work) is to create a bespoke combo using a textbox and a continuous form that looks like the dropdown. Has other benefits such as being able to use colour and/or richtext in the dropdown
I've done what you suggested to replace datasheet subforms because they also provide very limited customisation. It would be nice if the MS Access team added more modern form controls, like I have seen in web forms.
 
My goal is to display gray text in a combo box that does not contain a value (null), indicating that the user should select a value from the list.
The Windows API way to achieve this would be to set a cue banner.
I'm not sure if this works with an Access control that not currently has the focus.

 
With the use of a union query, conditional formatting and because the form is unbound setting the combo box value to 0 in Form_Load, I was able to get your affect.

Code:
Private Sub Form_Load()
mTboxWidth = Me.txtTemp1.Width
Me.cmbUnion = 0
End Sub

Added tblOne and qryOne for combo box source.
Code:
SELECT
    tblOne.ID,
    tblOne.Field1
FROM
    tblOne;

UNION ALL
SELECT
    TOP 1 0 AS ID,
    "<Select a Value>" AS Field1
FROM
    tblOne
ORDER BY
    tblOne.ID;

1762348756325.png

1762348785122.png
 

Attachments

The Windows API way to achieve this would be to set a cue banner.
I'm not sure if this works with an Access control that not currently has the focus.

When focus is on bound controls, at the bottom of the form it displays whatever comments were added to the fields in table design.
 
With the use of a union query, conditional formatting and because the form is unbound setting the combo box value to 0 in Form_Load, I was able to get your affect.

Code:
Private Sub Form_Load()
mTboxWidth = Me.txtTemp1.Width
Me.cmbUnion = 0
End Sub

Added tblOne and qryOne for combo box source.
Code:
SELECT
    tblOne.ID,
    tblOne.Field1
FROM
    tblOne;

UNION ALL
SELECT
    TOP 1 0 AS ID,
    "<Select a Value>" AS Field1
FROM
    tblOne
ORDER BY
    tblOne.ID;

View attachment 122167
View attachment 122168
That's also a completely different approach, so thank you too for this idea. But I'm still inclined to use Colin's option 2.
 
The Windows API way to achieve this would be to set a cue banner.
I'm not sure if this works with an Access control that not currently has the focus.

Interesting approach, I'm not familiar with this API yet. I'll take a closer look at it.
 
@sonic8 : Unfortunately, the API does not seem to work with Microsoft Access form controls (only with 'real' Windows controls as used in a UserForm).
 
@sonic8 : Unfortunately, the API does not seem to work with Microsoft Access form controls (only with 'real' Windows controls as used in a UserForm).
What is the difference between a Access form control and a 'real' Windows control?
The kind of binding?
 
What is the difference between a Access form control and a 'real' Windows control?
The kind of binding
Access form controls are managed by its own runtime environment and can be easily "bound" to a data source (like a table field) for automatic data interaction, while real Windows controls (like those in Windows Forms applications) are part of a broader programming DotNet framework and are typically "bound" using more code-based mechanisms, such as a BindingSource control or data models. Access controls handle many of the data-linking details for you, whereas Windows controls require more explicit configuration.
 

Users who are viewing this thread

Back
Top Bottom