Hi!
Some time ago I ask a question about how to change a default-value for a control in a form. I got the answer that it wasn’t possible.
I and my co-worker thought some more about this and he come up with an idea that worked. The solution is:
DoCmd.Close acForm, FormName
DoCmd.OpenForm FormName, acDesign
Forms!FormName.Control.DefaultValue = Chr(34) &_
StringExpression & Chr(34)
DoCmd.Close acForm, FormName, acSaveYes
DoCmd.OpenForm FormName
First we close the form and reopen it in design view. Then we change the value, (The Chr(34) stands for “ and it’s used to get the “” around the expression, this is necessary when dealing with string expressions. After that we close the form, save it and open it again.
There is something’s to think about with this solution. The open and close event will run because of that we close and open the form throughout the procedure. Therefore it is important to think about what those events do before using this procedure.
Any suggestions for improvements is always welcome, Markus Larsson
Some time ago I ask a question about how to change a default-value for a control in a form. I got the answer that it wasn’t possible.
I and my co-worker thought some more about this and he come up with an idea that worked. The solution is:
DoCmd.Close acForm, FormName
DoCmd.OpenForm FormName, acDesign
Forms!FormName.Control.DefaultValue = Chr(34) &_
StringExpression & Chr(34)
DoCmd.Close acForm, FormName, acSaveYes
DoCmd.OpenForm FormName
First we close the form and reopen it in design view. Then we change the value, (The Chr(34) stands for “ and it’s used to get the “” around the expression, this is necessary when dealing with string expressions. After that we close the form, save it and open it again.
There is something’s to think about with this solution. The open and close event will run because of that we close and open the form throughout the procedure. Therefore it is important to think about what those events do before using this procedure.
Any suggestions for improvements is always welcome, Markus Larsson