repeating the same date in a text box on a form

Conor

Registered User.
Local time
Yesterday, 22:11
Joined
May 3, 2007
Messages
18
Hello forum,

I'm a rookie looking for what I hope is a simple solution that I cannot find in help system. I have a data entry form with a date in a text box. I am entering one record at a time. I need to be able to change the date, but for multiple iterations, the date is the same. That is, I may enter 20 records with the same date before changing the date. Is there a simple way to make the date persist in the field until I enter a new value? Thanks in advance for any help.

Conor
 
In the properties of the control under the 'data' tab, there is a row called 'default' data. If you put in: Date(), then when you open a new record, that control will always default to today's date.

If you want to set some default other than today's date you can manipulate this somewhat. Let's say you always wanted it to be yesterday's date: DateAdd("d", -1, Date())

If you wanted to set this default every time you started, you would probably need to create a global date type variable and set that variable thru your start-up form each time you start a new session.

-dK
 
If you are using a main / sub form then have the date in an unbound field on the main form and get the date field in the sub form to reference this field. It will always be what is in the main date until you change the date manually.
 
Thanks, guys. Those sound like good techniques to put in my tool box. However, it seems that in the absence of a main/sub form arrangement, a random date, unrelated to today's date, cannot be maintained. Oh well...

Thanks for your input.

Conor
 
In your form, you can use the AfterUpdate event of the control holding your data to set the DefaultValue for the field. From that time forward, until you either manually change the data or close your form, the data will be entered automatically in each new record. The syntax varies slightly, depending on the datatype of the data:

For Date fields

Code:
Private Sub YourDateControlName_AfterUpdate()
If Not IsNull(Me.YourDateControlName.Value) Then
  YourDateControlName.DefaultValue ="#" &  Me.YourDateControlName & "#"
End If
End Sub
For Text fields

Code:
Private Sub YourTextControlName_AfterUpdate()
If Not IsNull(Me.YourTextControlName.Value) Then
  YourTextControlName.DefaultValue = """" & Me.YourTextControlName.Value & """"
End If
End Sub
For Numeric fields

Code:
Private Sub YourNumericControlName_AfterUpdate()
If Not IsNull(Me.YourNumericControlName.Value) Then
  YourNumericControlName.DefaultValue = Me.YourNumericControlName.Value
End If
End Sub
 
Shazam!! Works like a charm. Many thanks, Virginian.
 
... From that time forward, until you either manually change the data or close your form, the data will be entered automatically in each new record.

Really now? Now, that is awesome - adding to me bag of tricks.

Thanks for posting!

-dk

EDIT: Unfortunately, it seems I have to spread some rep around before I can tip your scales again ... but how about virtual pat on the back?
 
Glad to help! That's what makes Access/VBA so much fun; there's always some new trick to learn! :D
 

Users who are viewing this thread

Back
Top Bottom