can't set defaultvalue to combobox

associates

Registered User.
Local time
Today, 11:00
Joined
Jan 5, 2006
Messages
94
Hi,

I was wondering if anyone might be able to help me here. I was trying to set a defaultvalue for the combobox on another form. It works but shows a different value from what i want it to be.

Code:
Private Sub CM_SetDefaultYear_Click()

    [Forms]![CHW_Startup]!CB_Year.DefaultValue = "2010/11"

End Sub

After clicking the button, the value of the combobox becomes 182.727 instead of 2010/11.

Thank you in advance
 
2010 divided by 11 is 182.727 and that is why the value is changing. Try enclosing the value in single quotes within double quotes

ie "'2010/11'".
 
Thank you Dennisk for your help.

Yes, it works now. But how do i make it changed permanently unless someone comes along and set the default value to be some other years. What i mean is that at the moment, the Year combo-box shows "2008/9" because that year is written in the default value field under the properties of the combo-box. Then, i thought it may help a lot if i created a form to allow user to change the value of default for the year and i made it.

So what the problem now is as soon as i close the whole database and re-open it, i found the year combo-box showing the year "2008/9" when it should be showing the year "2010/11" that i just changed it thru the form.

Thank you in advance
 
Just put a button on the form that says something like "Make Current Value Default". In the button's OnClick event, put:

Code:
YourComboBoxName.DefaultValue = "'" & YourComboBoxName & "'"
 
Hi Moniker,

Thank you for your reply.

Yes, that works and what you've written there is what i've got at the moment in my codes. It does change the default value of the combo-box. However, the value stays there as long as the database isn't closed or shut.

As soon as the database is closed up and re-open, the default value is changed back to its initial value again namely "2008/9". What i want is simply this. Once the user changes the default value ,eg, from 2008/9 to 2010/11, in the combo-box, i'd like to see the default value set to 2010/11 after the database is closed and re-open, not default value coming back to 2008/9.

hope you understand my explanation

Thank you in advance
 
It sounds like you have the default value placed in the table design and not on the control's property sheet. Is that the case?
 
Hi Moniker,

No, I actually have the value "2008/9" set by typing into default value on the control's property sheet. Then, i decided to be able to modify or re-set the default value thru coding on the form.

Thank you in advance
 

Users who are viewing this thread

Back
Top Bottom