Default value based on combobox selection (1 Viewer)

sadiq92

New member
Local time
Tomorrow, 00:38
Joined
Jun 4, 2020
Messages
29
Hello

I have one form . I want one of the text boxs default value to be depends on combobox selection. How I can do it ?
 

theDBguy

I’m here to help
Staff member
Local time
Today, 14:38
Joined
Oct 29, 2018
Messages
21,469
In the AfterUpdate event of the Combobox, you could try something like:
Code:
Me.TextboxName.DefaultValue = """" & Me.ComboboxName & """"
Hope that helps...
 

sadiq92

New member
Local time
Tomorrow, 00:38
Joined
Jun 4, 2020
Messages
29
In the AfterUpdate event of the Combobox, you could try something like:
Code:
Me.TextboxName.DefaultValue = """" & Me.ComboboxName & """"
Hope that helps...

where I put the default value?

for example if the default value is “ London “ , how I put it on the code?
 

theDBguy

I’m here to help
Staff member
Local time
Today, 14:38
Joined
Oct 29, 2018
Messages
21,469
where I put the default value?

for example if the default value is “ London “ , how I put it on the code?
Hi. I thought you said the default value would depend on what was selected in the Combobox? If so, you don't put "London" in the code. Instead, you select "London" from the Combobox, and the code will pick it up for you.
 

sadiq92

New member
Local time
Tomorrow, 00:38
Joined
Jun 4, 2020
Messages
29
Hi. I thought you said the default value would depend on what was selected in the Combobox? If so, you don't put "London" in the code. Instead, you select "London" from the Combobox, and the code will pick it up for you.
no you misunderstand me.

for example , If I select “England” from Combobox , I want thr default value of textbox to be “ london “.

If I select other than England , I want the textbox to be empty
 

theDBguy

I’m here to help
Staff member
Local time
Today, 14:38
Joined
Oct 29, 2018
Messages
21,469
no you misunderstand me.

for example , If I select “England” from Combobox , I want thr default value of textbox to be “ london “.

If I select other than England , I want the textbox to be empty
No, I don't think I misunderstood what you asked for. Did you try the code I posted? Since you don't know ahead of time what the user will choose from the Combobox, you can't put it in the code. The code I gave you should put London, if the user selects London, and it should automatically put England, if the user selects England. Give it a try and let us know what happens.
 

Isaac

Lifelong Learner
Local time
Today, 14:38
Joined
Mar 14, 2017
Messages
8,777
It sounds like you want a lookup based on Countries and Cities. Rather than the same value as the combobox. Is that correct?
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 17:38
Joined
Feb 19, 2002
Messages
43,266
It's actually a little more complicated. You need to add another column to the lookup table to include the City name and you need to include the city name in the RowSource query of the combo. Do not forget to change the column count and column width properties when you add the THIRD column to the RowSource. The code below ASSUMES that CityName is the third field in the RowSource query. It is reverenced as .Column(2) because the columns of the RowSource are a 0-based array. The first column is .column(0) and that is the uniqueID which is also the default or .Value property. The second column which is the CountryName in this case and is referenced as .Column(2) if you need to reference it in code.

Me.TextboxName.DefaultValue = """" & Me.ComboboxName.Column(2) & """"
 

Users who are viewing this thread

Top Bottom