Default text in a bound combobox (1 Viewer)

theDBguy

I’m here to help
Staff member
Local time
Today, 13:40
Joined
Oct 29, 2018
Messages
21,358
Oops. Just went back to that combo and realised I'd changed it by mistake. It SHOULD be 4
And, did it make any difference? Just curious...

Also, is this on A365 only?
 

chacham

Member
Local time
Today, 16:40
Joined
Oct 26, 2020
Messages
45
Actually, it works even if the first field is hidden

View attachment 98145

View attachment 98146

View attachment 98147

As soon as you click in the combobox the default text disappears automatically
1644439220693.png
1644439244865.png
1644439452889.png


This does not work for me. What am i missing?
 

isladogs

MVP / VIP
Local time
Today, 20:40
Joined
Jan 14, 2017
Messages
18,186
Try making the first column slightly >0 e.g. 0.01or even 0.001

The feature has been available for many years - not just 365
For more info, see my article:
 

chacham

Member
Local time
Today, 16:40
Joined
Oct 26, 2020
Messages
45
Try making the first column slightly >0 e.g. 0.01or even 0.001
Well, that became .0007, and the default text did show up! However, now after the name of the doctor is chosen from the list part, the top shows the id instead of the name.

Also, can this show gray instead of black?
 

isladogs

MVP / VIP
Local time
Today, 20:40
Joined
Jan 14, 2017
Messages
18,186
If the ID field is the first column (column 0) it shouldn't be visible with a width close to zero.
I explained how to make the default text grey in post #13.

Have you read my web article? If not, please do so.
 

chacham

Member
Local time
Today, 16:40
Joined
Oct 26, 2020
Messages
45
If the ID field is the first column (column 0) it shouldn't be visible with a width close to zero.
Then i'm doing something wrong, but i do not know what.

I explained how to make the default text grey in post #13.

Missed that, oops!

To get grey prompt text for this example, first set the control forecolor to grey, then the format property could be: [Black]@;"Enter Last Name"
The prompt text will be grey but the text entered by the user will be black

That's backwards and confusing, but if it works, it works. Thank you.

Have you read my web article? If not, please do so.
Nope. I wasn't sure what it was addressing because it spoke of color. I see the part you were referring to now though.

I may try this later, but for right now, i got it working on three comboboxes and i'm not sure i want to keep trying to redo it when it is already working perfectly. Then again, this seems cleaner, if a bit confusing.
 

isladogs

MVP / VIP
Local time
Today, 20:40
Joined
Jan 14, 2017
Messages
18,186
The default colour needs to be grey because that is what you see before entering any text.
The format property e.g. [Black]@;"Enter Last Name" tells you what colour entered text will be (black) and gives the value when nothing is entered (Enter Last Name)

I suggested you read that article for a reason - it explains the format property of each datatype
You could at least do me the courtesy of spending a few minutes reading that to understand the ideas behind this approach.
Then it might be less confusing to you
 

chacham

Member
Local time
Today, 16:40
Joined
Oct 26, 2020
Messages
45
You could at least do me the courtesy of spending a few minutes reading that to understand the ideas behind this approach.
Then it might be less confusing to you
I indeed did skim the article. I logged out of work for the day, so i didn't feel like going to in depth right now.

By "confusing" i did not mean it was hard to understand, rather, that it is backwards, in that the forecolor refers to the default, and the color specified by the default is the main color. Looking at that while not familiar with this behavior would likely confuse anyone until they read about the bahavior.
 

CJ_London

Super Moderator
Staff member
Local time
Today, 20:40
Joined
Feb 19, 2013
Messages
16,553
format property is usually one of the drums I bang :whistle:

@chacham What Colin is saying for it to work in a combo is the bound column needs to be the first visible column (i.e the one that shows when the dropdown is closed). Doesn't matter whether the controlsource is populated or not.

In your case, you may need to bind to the hidden PK so the format option won't work unless you can do the following

1. leave the controlsource blank - as you have in post#22
2. set the bound column to column 2 - you have column1 in post#22
3. in the combo after update event some code along the lines of
Code:
me.DoctorFK=cboDoctor.column(0)
or perhaps you just need to make a change to building your filter/criteria (i.e. include .column(0))
4. if the control is bound you will also need some code in the form current event to set a value - along the lines of
cboDoctor=dlookup("DocName","tblDoctors","DoctorPK=" & me.doctorFK)

Note this won't work in a continuous form if the combo is in the detail section

Which is why my suggestion in post#9
 

chacham

Member
Local time
Today, 16:40
Joined
Oct 26, 2020
Messages
45
format property is usually one of the drums I bang :whistle:

@chacham What Colin is saying for it to work in a combo is the bound column needs to be the first visible column (i.e the one that shows when the dropdown is closed). Doesn't matter whether the controlsource is populated or not.

In your case, you may need to bind to the hidden PK so the format option won't work unless you can do the following

1. leave the controlsource blank - as you have in post#22
2. set the bound column to column 2 - you have column1 in post#22
3. in the combo after update event some code along the lines of
Code:
me.DoctorFK=cboDoctor.column(0)
or perhaps you just need to make a change to building your filter/criteria (i.e. include .column(0))
4. if the control is bound you will also need some code in the form current event to set a value - along the lines of
cboDoctor=dlookup("DocName","tblDoctors","DoctorPK=" & me.doctorFK)

Note this won't work in a continuous form if the combo is in the detail section

Which is why my suggestion in post#9
I'm way too tired to appreciate that comment right now. :) Especially while working on someone else's project right now.

But i do have to ask. Do you think this is easier than the solution i posted originally?
 

CJ_London

Super Moderator
Staff member
Local time
Today, 20:40
Joined
Feb 19, 2013
Messages
16,553
Either mine or colins . You haven’t provided any context around this and the other combo’s you want to provide the same functionality- are they for searching/ filtering? Populating a record? Criteria for opening a form?
 

chacham

Member
Local time
Today, 16:40
Joined
Oct 26, 2020
Messages
45
@CJ_London, i'm sure your solution works, but i feel that my solution is easier. There's just so many steps in your solution. @isladogs solution seems more elegant, but, as i said, it seems confusing, and i already have something working. If i revisit this, i would likely try his solution again, even though it failed the first time around.

>are they for searching/ filtering? Populating a record? Criteria for opening a form?

The form is based on a query that refers to the two comboboxes, to which i added a third. When a selection is made, the form is refreshed so that the records in the form reflect the chosen facility, doctor, or now a third choice, patient.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 04:40
Joined
May 7, 2009
Messages
19,169
But i do have to ask. Do you think this is easier than the solution i posted originally?
you Already have a working db? why experiment more.
 

chacham

Member
Local time
Today, 16:40
Joined
Oct 26, 2020
Messages
45
you Already have a working db? why experiment more.
Because i'm quite the newb here, and beginning to work on someone else's project. I'm asking to make sure i'm not doing something stupid. Also, even solutions i don't take still teach me useful things!
 

CJ_London

Super Moderator
Staff member
Local time
Today, 20:40
Joined
Feb 19, 2013
Messages
16,553
well, you asked for comments - up to you as to whether you feel your method is best.

my final comment would be that with your method, you need more code to make cmbNH_default_text visible again in the event that nothing is selected

Good luck with your project
 

chacham

Member
Local time
Today, 16:40
Joined
Oct 26, 2020
Messages
45
my final comment would be that with your method, you need more code to make cmbNH_default_text visible again in the event that nothing is selected

I appreciate the comments! I also like to discuss and understand the pros and cons of the different methods. And, who knows, when i present it to the user tomorrow (this change is mostly for just one user right now), things might go wrong, and i might end up using your solution instead. :)

Yes, i do need to add code. But, the form already had code in the afterupdate events, so it was pretty easy to add another line or two.
 

Users who are viewing this thread

Top Bottom