default value in combo

irade92

Registered User.
Local time
Today, 07:26
Joined
Dec 26, 2010
Messages
229
How to put a default value in a combo that reads values from a query.
Thanks
 
So how are you wanting to determine what the default is?
 
So how are you wanting to determine what the default is?

So...let say that one of the values I choose I want to be default value..because it is used mostly.
Thanks
 
If you know what the default should be, and it will be available from the row source, you can just set the combo's default property to the value you are going to want from design view. Or you can use code in the form's On Load event.
 
I use control = control.DefaultValue
 
What you're actually doing with the Value from this Combobox needs to be considered.

Is the Combobox Bound to a Field in the Form's underlying Table or Query, i.e. is there a Field Name in the Combobox Control Source Property? The simplest way, in this scenario, would be using the Default Value in the Property pane, as Bob suggested.

If you want to do this through code for this scenario you could also use something like
Code:
Private Sub Form_Current()
 If Me.NewRecord Then
   Me.ComboBoxName = "Default Choice"
 End If
End Sub
If, on the other hand, this Combobox is Unbound, and you plan on using the Value selected for something else, such as assigning it to a Textbox or using it as part of a calculation, that would be different. We frequently do things like this using the Combobox AfterUpdate event. The problem here is that when the Value is selected using code or thru the Default Value Property, the AfterUpdate event doesn't execute! You have to explicitly Call the AfterUpdate event.

In this scenario I'd use
Code:
Private Sub Form_Current()
 If Me.NewRecord Then
   Me.ComboBoxName = "Default Choice"
   Call ComboBoxName_AfterUpdate()
 End If
End Sub
If you subsequently elect to select another Value from the Combobox, using your mouse and the Combobox, its AfterUpdate event will be run again, based on the new Value.

Linq ;0)>
 
Last edited:

Users who are viewing this thread

Back
Top Bottom