Inserting Date only into a control

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
 
T

tina

in VBA, use

Date

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

hth
 
N

Neil Warwick

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
 
V

vseale

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


.
 
T

tina

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top