PDA

View Full Version : Problem to set the standard value in a combobox in a form



TonC
06-26-2017, 10:04 AM
Hello,:hi:


I’ve got a form with a combobox named “Tijdvak”
The recordsource is a table called “tblTijdvak” , with autonumbering ´Tijdvak_Id´ , and a short textfield with the name
“Tijdvak”.

In the table “tblTijdvak” is the id. nr 78 , and the name of the textfield is wk26.

I put in the form, in the combobox field “Tijdvak” the next standardvalue I quote, ="wk"&(Format(Date();"ww"))
I hoped that the outcome was simple wk26, that is the current week of the year.
But there nothing to see in my form in the combobox “Tijdvak” when I open this form.

To check if my expression was correct in the immediate window I typed:
?"wk"&(Format(Date();"ww"))
Now it works fine. The result was wk26

How can I get the same result in my combobox in the form?

Thanks in advance.
TonC

OBP
06-27-2017, 03:16 AM
I do not know what version of Access you are using, but in all versions up to 2007 the controlling characteristic for a combo box (or other field) is the
Default Value
So try using your expression in that control on the Combo Box's "Data Tab" in design mode.

HiTechCoach
06-29-2017, 02:01 PM
Note: The default value must be a valid for the bound coulmn (should be the primary key). If the bound column is hidden (column witdth = 0), you still must set the default based on the bound column. Not what is displayed to the user.

In your example, the bound column should be Tijdvak_Id. This a is an auto number. The default value must be a integer. An autonumber will never equal ="wk"&(Format(Date();"ww")).

TonC
07-15-2017, 03:15 PM
Hello HiTechCoach,

Yes, you are right. Its stupid from me to put a string in a autonummer field. Is there perhaps a solution?