By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,656 Members | 1,775 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,656 IT Pros & Developers. It's quick & easy.

Setting default value

100+
P: 418
My combo box is pulling data from tblAccounts using its PK (auto number) AccountID but displaying AccountNo (text).

Is it possible to set the default value for this combo box to one of the AccountNos?

Let me explain
AccountID = 1
AccountNo = 4xxxx

I would like cboAccount which is a combo box on a subform (sfrmGrantBudget) to display "xxxxx" as a default value. Is it possible? When I tried, it displays the AccountID for AccountNo XXXXX

tblGrantBudget is related to tblAccounts with a join type of 1.

Thanks.
Apr 30 '09 #1
Share this Question
Share on Google+
5 Replies


Expert 100+
P: 1,287
M,
I had no problem setting a default for a combo box in a quick test. Is your combo box bound to column 1 (accountID) and displaying 2 columns, with the first 0"? Did you attempt to set the default value on the Data tab of the combo box properties to an account ID?
Apr 30 '09 #2

100+
P: 418
Answer to all your questions are YES.

On the Data tab: I have
Bound Column = 1
Control Source = AccountID
Row Source = SELECT tblAccounts.AccountID, tblAccounts.AcctNo, tblAccounts.AcctDescr FROM tblAccounts;

Format Tab:
Column Count = 2
Column Widths = 0"; 1";

I guess I must not be doing something right somewhere.
Apr 30 '09 #3

DonRayner
Expert 100+
P: 489
You need to set the "Column Count" property for the combo box to 2. Then if you only want it to display the AccountNo but not the AccountID you would set the "Column Widths" property to something like 0";2" thus hiding the first column containing the AccountID

What you end up with is a combo box that displays the AccountNo but is bound to the AccountID.
Apr 30 '09 #4

100+
P: 418
DonRayner:

I have no problem with displaying the data as you described. However, my problem lies when I select a default value to read, for example,
AccountNo as "4XXXX" it displays AccountID 91.

Thanks.
Apr 30 '09 #5

Expert Mod 2.5K+
P: 2,545
Hi. You are confusing the value of the account number displayed - the 4XXXXX bit - with the value of the bound column.

The default value in the case of a combo box applies to the bound column, regardless of which columns are visible and which are hidden.

As the controlsource of the combo is AccountID, presumably a long-integer number generated by an autonumber field in the related table, the bound value should also be a long-integer number.

In the example you give, the 4XXXXX bit corresponds to an AccountID of 1, so 1 should be your default value for the combo if that is the value you want to display. If the default value you want is a different account number, you will need to supply the actual ID number for that value (e.g. 91, say, or whatever other long-int ID value matches the account number concerned). You will see all of this more clearly if you do not set columns to hidden to begin with.

-Stewart
Apr 30 '09 #6

Post your reply

Sign in to post your reply or Sign up for a free account.