Set DefaultValue of Unbound Text Box to Last Selection

mikeTTI

Registered User.
Local time
Tomorrow, 11:55
Joined
Oct 7, 2007
Messages
41
I have a form I use as a dialog box to set reporting criteria.

There is an unbound text box [DateFrom] on the form.

When/before the form is closed I would like to set the default value of this text box to its current value. (there is currently no default value assigned).

I have tried the following both in the procedure for the 'exit' comand button, and in the OnClose event

Code:
Dim MyDate as Date

MyDate = Me![DateFrom]

Me![DateFrom].CurrentValue = MyDate

But it doesn't change the default value.

Any suggestions?
 
If you want to change the default value you will either need to open the form in design view (yes, even with code) and change the default :

Me.YourControlName.Default = WhateverHere
DoCmd.Save

Or you can save it to a table and then load it when the form loads.
 
Thanks Bob,

Do you still think I should use a variable to store the last date used?

Presumably once I am in design veiw the textbox will effectively be blank?
 
You would save it to a variable and then change into design view set the value and save and close.
 
Hey, guys, you're making me dizzy here!

mikeTTI said:
Me![DateFrom].CurrentValue = MyDate

There is no CurrentValue property in Access VBA! It would simply be

Me![DateFrom].Value = MyDate

or, since Value is the default property for textboxes, even more simply

Me![DateFrom] = MyDate

Bob said:
Me.YourControlName.Default = WhateverHere

Nor is there a Default property for textboxes! It should be (as Bob well knows)

Me.YourControlName.DefaultValue = WhateverHere

As to the question of the hour, instead of opening/closing the criteria form, why not simply leave the criteria form open, controlling its visibility instead? The unbound textbox would retain the last value entered without doing the song-and-dance we're considering here. Assigning a value to a global variable, closing the criteria form, reopening the criteria form in Design View, then assigning the global variable to the textbox DefaultValue seems like an awful lot of effort for what we're trying to do here!
 

Users who are viewing this thread

Back
Top Bottom