Inserting Date only into a control

  • Thread starter Thread starter Neil Warwick
  • Start date Start date
N

Neil Warwick

This is a real rookie question here, but I''ve had a brain
fade & need to get this sorted before I depart to Egypt
for a well earned holiday tomorrow!!

I want to use a bit of VBA code to to insert the date into
a field on my form.

What is the command to get just the date? I have used Now
() but get date and time, but I only want date.

Is there a command or do I have to reformat the date to
remove the time?

Thanks for helping someone in holiday mode!!


Neil
 
in VBA, use

Date

btw, you actually do get a time as well, but it defaults to midnight.

hth
 
I have to say that's what i thought, so I used the code
below to insert the date into a control when it gained the
focus, but it doesn't do anything. (The bruise on my
forehead is getting bigger!)

Private Sub Date1_GotFocus()
Form.Date1 = Date

End Sub
 
Try Date()
-----Original Message-----
I have to say that's what i thought, so I used the code
below to insert the date into a control when it gained the
focus, but it doesn't do anything. (The bruise on my
forehead is getting bigger!)

Private Sub Date1_GotFocus()
Form.Date1 = Date

End Sub


.
 
hmm, worked fine when i tested it. if the code you posted is exactly what
you're using, suggest you change it to

Private Sub Date1_GotFocus()

Me!Date1 = Date

End Sub

also, suggest you use the control's Enter event, rather than GotFocus. also,
the above code will always overwrite any existing value that is already in
the field. you may want to restrict the entry with

If Me.NewRecord Then
...

or

If IsNull(Me!Date1) Then
...

depending on your needs.

hth
 
Back
Top