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

Can a default value be set in a combo box?? 1

Status
Not open for further replies.

lachesis

Technical User
Sep 25, 2002
138
NZ
I'm really unsure about this one.

I want to populate a combo box with a default value if the user does not put one in. Problem is the bound column is record ID [column(0)], and this has no meaning given that the record ID is an autonumber. I want to default to a value in column(1).

cboCurrencyType
column(0) = recID
column(1) = cType

so...
col(0) col(1)
1 AUD
7 USD
5 NZD
11 JPY ... and so on.

Any ideas on this one?? I was thinking about itemdata(), but I dont know how to use it in this context.

thanks
L.
 
Are you saying that you know the cType but not the recID? If the cType won't change, just look up the recID once and use that. If it does change then, you can "look it up" at runtime:

cboCurrencyType = DLookup("recID","tblCurrencyTypes","cType='USD'")

Have you considered putting this as the combo box's Default Value (look on the Data tab of the property sheet), so it is already selected when the form loads?

Are you talking only about new record entry or also about viewing previously created records?
 
Thanks. I think the DLookup will do the trick. I was confused by the period filtering function in another combo box that needed selection before cboCurrencyType got focus.

L.
 
Oops unfortunately I can't use the DLookup on the originating table, as the period filtering combo box delimits the recID available to the cboCurrencyType rowsource.

The full rowsource for cboCurrencyType is:
column(0) = recID
column(1) = cType
column(2) = YrPeriod
column(3) = MthPeriod

so...
col(0) col(1) col(2) col(3)
1 AUD 2003 12
7 USD 2003 12
15 USD 2004 01
5 NZD 2003 12
11 JPY 2004 01
... and so on.

So the selection in the Period filter combo box (cboCurrencyPeriod) will act as criteria for the rowsource of cboCurrencyType eg. 2003/12 as filter would result in recID rowsource of 1, 7, 5 from the list above, not 15 or 11 (from period 2004/01).

When I use DLookup on tbl_Currency it just looks up the first instance of its criteria, not the filtered recordset.

Douh!
L.
 
Spoke too soon. Just extended the criteria of the DLookup function to dynamically include the values from cboCurrPeriodFilter.

thanks for pointing me down the right path.
L.
 
You're welcome. You could also have done this programatically with VB in a module, but sometimes it's easier to just use the built-in domain aggregate functions. :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top