This is some code I was working on a while ago, and posted on this Forum:-
It is supposed to save the current value of the [DateFrom] text box to the variable MyDate, then set the DefaultValue property of [DateFrom] to the value of MyDate, then save and close the form.
It returns the error message
As a test I used the MsgBox function above to read the value of MyDate. The resulting message box displayed the expected value, so MyDate is picking up the value from the text box and retaining it until after the Form is opened in design view.
Not sure why this isn't working. Or aternately does anyone have a better suggestion.
The text box sets a date range criteria for a number of queries.
I want like the value the user enters into the text box to become the default value for the next time the form is used.
It has been suggested previously to keep the form open instead of using the default value, but the application is frequently opened and closed, so this won't work.
Code:
Dim MyDate As Date
MyDate = Me![DateFrom]
DoCmd.OpenForm "LevyReportDialog", acDesign
Me.DateFrom.DefaultValue = MyDate
[COLOR=seagreen]'MsgBox MyDate[/COLOR]
DoCmd.Close acForm, "LevyReportDialog", acSaveYes
It is supposed to save the current value of the [DateFrom] text box to the variable MyDate, then set the DefaultValue property of [DateFrom] to the value of MyDate, then save and close the form.
It returns the error message
"The Expression you entered refers to an object that is closed or doesn't exist"
As a test I used the MsgBox function above to read the value of MyDate. The resulting message box displayed the expected value, so MyDate is picking up the value from the text box and retaining it until after the Form is opened in design view.
Not sure why this isn't working. Or aternately does anyone have a better suggestion.
The text box sets a date range criteria for a number of queries.
I want like the value the user enters into the text box to become the default value for the next time the form is used.
It has been suggested previously to keep the form open instead of using the default value, but the application is frequently opened and closed, so this won't work.