Display default value in ComboBox (1 Viewer)

eugzl

Member
Local time
Today, 11:20
Joined
Oct 26, 2021
Messages
125
Hi All.
Creates query with default value to populate the ComboBox:
Code:
SELECT DISTINCT DeviceType.DeviceTypeID, DeviceType.DeviceType,1 AS SortRow
FROM (Device LEFT JOIN DeviceType ON Device.DeviceTypeID = DeviceType.DeviceTypeID) LEFT JOIN Brand ON Device.BrandID = Brand.BrandID
WHERE (((Brand.BrandID)=[Forms]![f_Device]![cboBrand]));
UNION SELECT 0, "Select Type", 0 FROM DeviceType
ORDER BY SortRow, DeviceType.DeviceType;

Now when form is ran the ComboBox display a blank field. I would like when I ran a form default value "Select Type" will be display in the ComboBox. How to do that?

Thanks.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 11:20
Joined
May 21, 2018
Messages
8,463
need to set the value of the combobox.
me.somecombo.value = Me.someCombo.ItemData(0)

You may want to check first if it is null before doing that. Do not want to change a previously selected value.
 

eugzl

Member
Local time
Today, 11:20
Joined
Oct 26, 2021
Messages
125
need to set the value of the combobox.
me.somecombo.value = Me.someCombo.ItemData(0)

You may want to check first if it is null before doing that. Do not want to change a previously selected value.
In Form_Load event I insert that line:
Code:
Me.cboDeviceType.Value = Me.cboDeviceType.ItemData(0)
But it didn't help. Thanks.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 11:20
Joined
May 21, 2018
Messages
8,463

eugzl

Member
Local time
Today, 11:20
Joined
Oct 26, 2021
Messages
125
I don't have problem to display the default value for first combobox in cascade set. I cannot get result to display default value for 2nd, 3rd, and 4th cascade combobox. I tried to use Form_Load and Form_Current event. In both got error message:
1636428506287.png

In line Me.cboType.Value = Me.cboType.ItemData(0)
How to fix the problem? Thanks.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 23:20
Joined
May 7, 2009
Messages
19,169
it's cascading and the your first combo is set to "dummy" text.
therefore, the dependent combos probably has no list yet.
 

eugzl

Member
Local time
Today, 11:20
Joined
Oct 26, 2021
Messages
125
it's cascading and the your first combo is set to "dummy" text.
therefore, the dependent combos probably has no list yet.
Hi arnelgp. Thanks for reply.
Do you have idea how to display default value for cascade comboboxes (in my case 4 comboboxes) when form is ran?
Thanks
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 23:20
Joined
May 7, 2009
Messages
19,169
if all you combo has same Union query with 0 as (devicetype?),
you can set all combos to 0 on the Load event of your form:

me.combo1 = 0
me.combo2 = 0
me.combo3 = 0
 

eugzl

Member
Local time
Today, 11:20
Joined
Oct 26, 2021
Messages
125
if all you combo has same Union query with 0 as (devicetype?),
you can set all combos to 0 on the Load event of your form:

me.combo1 = 0
me.combo2 = 0
me.combo3 = 0
Insert like you suggested line in Form_Load event:
Me.cboType = 0
and when ran form got error message:
1636436309040.png
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 23:20
Joined
May 7, 2009
Messages
19,169
there is something in your combo that does not allow
the value to be set through vba.
without seeing your form i cannot comment any further.
 

Users who are viewing this thread

Top Bottom