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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Loading combo box 1

Status
Not open for further replies.

jrf

Technical User
Jan 4, 2001
15
US
I am using a combo box to select work the authorization for a preselected client. When the client is selected the afterupdate drops down the list and sets the focus, but the combo box itself remains blank until an item from the dropdown list is selected. As the first item is the correct item 90+% fo the time, I would like the box to be automatically populated with the first item unless another item form the list is selected.

How do I do this? Besides that, what is in the combo box before a row is selected? null, "", what?
 
Hi Jrf,

Can't you just set the default value to the 90% correct one.

Apologies if that seems flippant,

Jes
 
Jes, your reply doesn't seem flippant at all, I've spent a lot of time trying to set the default. However, I cannot come up with a way to reference the 1st (listrow(0)) and make any or all the columns from the query appear. Remember, there is no default until the previous combo box, picking the client, is selected. I've tried to do this on exit also, making that first row appear if I <enter> on the blank combo box with no row selected, but no go there either. At least the combo box rows are populated with this approach.
 
Ok try something like this
( Bear in mind that I don't know your tables, and this is assuming the combo box is populated )

On Load Event

-----

dim rst as recordset
dim dbs as database
dim query as string

set dbs = currentdb

query = &quot;Select ListOfThings From MyTable &quot;
query = query + &quot; ORDER BY ListOfThings ASC;&quot;
'Set the order above to match what you need

set rst = dbs.openrecordset(query)

if rst.bof = False then
' always check you got some results
' hopefully your 90% will be at the top of the list
combo.value = rst.fields(1)
endif

set dbs = Nothing

-----------------------------------------

I hope that helps, give me a shout if I'm on the wrong track,

Best,

Jes
 
In the AfterUpdate event of the first combo box put this command:

My2ndComboName = My2ndComboName.ItemData(0)

Then whenever the first combo is updated, the 2nd combo will be set to the value of the first item in the list.

HTH Joe Miller
joe.miller@flotech.net
 
Thanks for the help Joe but using the .itemdata(0) didn't do a thing whereever I put it.

I've tried versions of that along with trying several other approaches including using .listindex(x), etc to no avail. Using .listindex(0) will actually put the correct item into the combo box window but then blows the rest of the sub due to error 7777 &quot;wrong use of listindex&quot;
 
Well I tested itemdata before suggesting it and it does work.. I can send you a working example if you provide me your email address, or you can send me your db and i can take a look.

Joe Miller
joe.miller@flotech.net
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top