Current date as default value in text box.

silversun

Registered User.
Local time
Today, 05:42
Joined
Dec 28, 2012
Messages
204
Hi everybody,
I have an unbound form, trying to show the current date in a text box. When I put this "Date()" expression in Default Value property of the text box it shows the same word "=Date()" in the text box rather than the actual date when i open the form in from view.
I've tried many times from different ways to get it work but it doesn't work at all.
Could you please help me on this?
Thank you
 
it should work when the textbox is bound:

default value: =Date()
 
Using default value =Date() Without quotes should work in an unbound control but not in a bound control.

To do this in a bound control, you could enter this in the form current event
Code:
me.textboxname=Date
The trouble with that is it will always show the current date even if the table record is something else
 
Last edited:
You could use in the Current event

Code:
If Me.NewRecord then
  Me.txtBoxName = Date
End If

I am sure I have used that method in the past for some reason.?

Edit: After a test

The Expression builder uses

=Date()
 
Hi,
Thanks for help but for some reason neither one works. I have done that before and it was working but now I can't make it. It either gives me error or shows Date() only.
I used the expression without quotes obviously. I even tried to add a bounded control to show the date but that is not working either.
The error when I use Me.txt_service_date = Date() in current event is:
"MS Office can't find the object 'Me'
If Me is a new macro or macro group, make sure you have saved it and that you have typed its name correctly."

It should be a simple fix but not before I figure it out.... :(
Please keep helping
 
Me is only available when your code is inside the form/report.
 
To expand on arnel's point, use an event procedure for the Form_Current event instead of a macro. The Me. Syntax will then work

However, if its an unbound control it should work using the default value property and without needing code
 
@ isladogs
I am thinking about something in my database that prevents the current date function from working. I don't have the option of "Repairing Database" available.
What would you do if an unbound control doesn't show the date in your computer?
i just created a new form and using the Date() function I can get the current date in an unbound control without hassle, very easy and simple but now it is not working in the older form. There should be something in settings or the way I have messed up with my form. :(
Tnx
 
Last edited:
If your control is bound to a field then use


Me![ControlName].DefaultValue = Date
Or you could set the default Value on the properties sheet by using
=Date()


hope it helps mick
 
You are right, I have done that before this project. Even in this project (form) it was working that way (2-3 weeks ago) but now for some reason it is not working. I even created a new form and used the same method you and other people suggested and it worked very well.
I believe I have messed up something in my form somewhere that it prevents this function from working.
This is not about coding anymore, it is about how to fix the form. :(
 
You are right, I have done that before this project. Even in this project (form) it was working that way (2-3 weeks ago) but now for some reason it is not working. I even created a new form and used the same method you and other people suggested and it worked very well.
I believe I have messed up something in my form somewhere that it prevents this function from working.
This is not about coding anymore, it is about how to fix the form. :(
Maybe it's a corrupted form. Try creating a new form to see if you have the same problems.
 
DB Guy beat me to it.
As another form works correctly, its almost certainly that your form is corrupted.
Make a backup then try decompiling to remove any corrupted code. See http://www.fmsinc.com/microsoftaccess/Performance/Decompile.asp
Then recompile your code and fix any compilation errors.

If that doesn't fix it you may be able to import all objects and code into a new form but if a control is corrupted that won't help. Final option is to recreate the form from scratch
 
Have you tried just adding another control with that default value.?
 
@ Gasman
Yes. I have. It doesn't fix the issue.
I am now creating a new form from scratch. :(
 
@ isladogs
Yes I did. It didn't help. So I created a new form and now I can see the date() function working.
Thanks for your help and everybody else's
 
@ isladogs
Yes I did. It didn't help. So I created a new form and now I can see the date() function working.
Thanks for your help and everybody else's
Hi. Glad to hear you got it sorted out. Good luck with your project.
 

Users who are viewing this thread

Back
Top Bottom