Display default value in ComboBox

eugzl

Member
Local time
Yesterday, 23:08
Joined
Oct 26, 2021
Messages
127
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.
 
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.
 
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.
 
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.
 
it's cascading and the your first combo is set to "dummy" text.
therefore, the dependent combos probably has no list yet.
 
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
 
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
 
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
 
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

Back
Top Bottom