Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

automatic selection of 1st item in combobox

Status
Not open for further replies.

bfellows

Technical User
Sep 17, 2002
10
US
I have a two comboboxes on a form. The first selects the name of a vessel in the database, and the second selects the policy year (insurance) for that vessel.

each vessel has a different history of policies. i've managed to get the term combo box choices to list all the items i want, with it requerying each time i select a different vessel.

my question:

to make the form idiot-proof, i would like to automatically select the 1st item on the combobox containing the years, after the vessel combobox is changed.

does access provide a quick (or even no-so-quick) way to do this?

thanks
 
Go to the event properties for the vessel name combo box and under after update event procedure type this code:

DoCmd.GoToControl "Year"
Me.Year.Dropdown
Me.Year.DefaultValue = Format$(Date, "YYYY")

Please note that this will dropdown the year combo box and then select the current year everytime you change the vessel name. This is assuming that on the year combo box the selection is 2002, 2003, 2004, etc.
 
that gets me partway there, i think. but the problem is that the the dates won't necessarily be consecutive up to current (the idea is actually to pick the most recent year). it could potentially go 2000, 2001, 2003 or 2000, 2001, 2002. in each case, i would want to select the most recent. i figured the easiest way would be to just take the value in the top spot of the combobox, since it is sorted in descending order.
 
I guess I'm not following how the year combo box would change its selection...this data should be static.

In any case case since the data is in descending order, just replaced Format$(Date, "YYYY") with the first year in the combo box i.e. if the sort is 2000, 2001, 2002, etc
type 2000 as the default value.
 
what i'm trying to do is to create a new insurance application based on a recent year's application, using much of the same data.

the first combo box selects the vessel, which could have any number of years' applications, up to, but not necessarily including the current year. each time the vessel combobox changes, the year combobox is refreshed to list the years to choose from, valid only for the vessel selected.

i was looking hopefully at the listindex property, but the access help file says it's a read-only property that i can't change myself.

was wondering if there was an operation to just select the top item in the box because there may not necessarily be an application entry for 2003, if say the policy was effective in 2002 and then extended to expire smometime in 2004.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top