Combo Box Defaulting to first line

bstice

Registered User.
Local time
Today, 11:03
Joined
Jul 16, 2008
Messages
55
Hello all,

Simple question - How do I build a combo box so it defaults to the first real value in the list? Currenly, the default is blank? Thanks

Brennan
 
Well, I guess for the default value, you can put something like this:

=DFirst([YourField], "YourTable")
 
Works great - the only issue is that I have a second combo that updates based on the first. When I change the lst combo, the second still has a null or zero value in the field displayed in the 2nd combo. How can I get it to display the first record in that field? Thanks
 
Use form's OnCurrent event to requery the second combobox (you may need to make sure the first combobox is up to date as well).
 
well, you can have it do a dlookup as defaultvalue

=dlookup([YourField2], "YourTable", "lookupfield = " & me.combo1)

Basically, the field that your second combo is based on, from your table, where a certain field is equal to me.combo1

However, you may have to change me.combo1 to the default value of combo 1 (dfirst.......)
 
An alternative within VBA, using form's OnCurrent event:

Code:
Me.MyComboBox.DefaultValue = Me.MyComboBox.ItemData(0)

I wanted something that wouldn't send in another query to the backend and merely used what was already had, and this works well for a combobox that could have different rowsource.
 
Banana's suggestion is the right one. If DFirst() has been working, it's just been a fluke! From Access Help:

Access Help said:
You can use the DFirst and DLast functions to return a random value from a particular field in a table or query when you simply need any value from that field.
 
Gee whiz... why call it DFirst if it returns a random value? :confused: I'd thunk it'd be called DRand, wouldn't you?
 
Hey, you're talking about MICROSOFT-in-the-head! :D

That's not much different than having a property named Data Entry that can be set to No and still allow you to enter data!
 
Okay, okay, okay! :D

I still think the default user "Admin" still wins the "FUMP!" award. :D
 

Users who are viewing this thread

Back
Top Bottom