Set the default value on a Combobox (1 Viewer)

itmasterw

Registered User.
Local time
Today, 03:55
Joined
Oct 31, 2005
Messages
45
Hi,
I am trying to set the default value on a combobox. And maybe I am saying this wrong for wha tI want to do, if so I am sorry.
I wrote SQL statement that populates the combobox, and that works; but when I ran the application initially the combobox is blank. If I click the arrow I can see and click on an entry and it works, but I want the first value in the list to appear there in the box before the user clicks. So I tried the flowing code but now instead of a blnk or the entery, I get "#Name?"
Which I hovered over the variable Srt and it has the right value in it, am I using the Me.cobMenu.DefaultValue Wrong?
cob is the combobox and I am using MS Access 2010.

Any ideas would be appreaciated.

Thank you

My Code:
Code:
 Srt = rs!CombobBox_Name

Me.cobMenu.DefaultValue = Srt[ /CODE]
 

Ranman256

Well-known member
Local time
Today, 03:55
Joined
Apr 9, 2015
Messages
4,338
in the ON CURRENT event of the form, set the combo to the 1st item in the list.

Code:
sub form_onCurrent()
 cboBox = cboBox.itemdata(0)     'in vb, items start with zero.
end sub
 

itmasterw

Registered User.
Local time
Today, 03:55
Joined
Oct 31, 2005
Messages
45
Thanks for the reply and help.
I could not get it to work in Current, but I put you suggestion in the form load and it worked great.
Thankls
 

Users who are viewing this thread

Top Bottom