Set Default Combobox Value?

woodman650

Always confused.
Local time
Today, 15:01
Joined
Jan 22, 2005
Messages
55
Can anyone tell me how you set a default value in a combobox? In my rowsource field I'm working with the values "Original";"Copy", and I just want the default to be "Original", so the user doesn't have to open up the combo everytime to choose one or the other... only if they need to change it to "copy". Hope that makes sense. anyone know? thanks!
 
Hello:
Yes I can tell you how to do that.
First: Make sure that "Original" is in your combo list.
Second on the FormOpen event of your form place the following code:
'
Private Sub Form_Open(Cancel As Integer)
'Set the combo box to display a default value.
YourComboBoxName = YourComboBoxName.ItemData(3)
'
End Sub
The "ItemData(3) is the position in your combo box list for the item "Original" Numbering Starts from 0 and goes up from there.
Regards
Mark
 
You can also set the .DefaultValue property of the control in design view.
 
hi whats the syntax for assigning it in the field in design view. i HAVE TRIED

[cboMYCOMBO].[ItemData](1)

but still is blank
 
There an item on the Data tab of the control's property sheet in design view called DefaultValue.
 
yes i understand where to put the information but i dont know what to put in the field, i have a similair prob to the post above i will go into more detail. I have a field called accStatus which looks up another table called tblStatus this has 2 fields:id and status.
The accStatus field has a dropdown list linked to the tblstatus. ID width is 0 as to only see status in the dropdown menu. The datatype of field accStatus is a number. The options for status are: open, pending,closed. And i want the closed option to be displayed in the dropdown fields by default. if however the user changes the value this will then be loaded when the form is next loaded. Hope this is clear - i have looked everywhere for an answer to this but i am really struggling.
 
yeah, that's what I was wondering (^), what to actually put into the defaultvalue field. I think this is the ideal way to go...

Mark, the VB doesn't work for me. I get an error when opening the page... also, will this work if more records are added using this form one after the other?
 
woodman650 & 50ld13r,

Have a look at the attached sample, it may help you with your problem.
 

Attachments

ahh, excellent example. but what if I'm not pulling values from a table or query?... what if my values are stored in the actual combobox?
 
ohh, I am the master of answering my own questions by looking at the Microsoft help docs. haha. Ok, I feel kind of dumb asking now. So in the table field, under "default value", I enter in "Original". Now, when I view the combobox, "Original" appears and I've got the option to drop down and select "Copy" if I want to. Easy beans. thanks for the SQL approach though guys :)
 

Users who are viewing this thread

Back
Top Bottom