Update a text box

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

I have a form that is connected to a query of so many fields among is a date
field. I would appreciate assistance on the syntax for the automatic update
of the date text box on the form connected to the date field on the query
with the current date. This can through entering a dot (.) in the text box,
then hit return or through using some combination keys when the text box gets
the focus.

Thanks for your expected support.
 
Alylia said:
Hello,

I have a form that is connected to a query of so many fields among is a date
field. I would appreciate assistance on the syntax for the automatic update
of the date text box on the form connected to the date field on the query
with the current date. This can through entering a dot (.) in the text box,
then hit return or through using some combination keys when the text box gets
the focus.

Thanks for your expected support.

You could use the textbox's Got Focus event to set it's own value to
today's date.

However, this would always happen when it got focus, and would overwrite
any existing data you already had in there. It might also be a problem
when you were just using your form to view the data and not edit it. It
might appear that the record was edited, just by getting the date changed.

That being said, here's the code, but I would recommend putting it in
another location that might be more appropriate to actual changing the
record, but that's your call.

Private Sub txtYourTextbox_GotFocus()
txtYourTextbox.Text = Date
' or format it to your date specs: txtYourTextbox.Text = Format(Date,
"mm/dd/yyyy")
End Sub
 
Exactly when you want this date field to be updated with the current date is
not clear. If you want it to update for new records only, then make Date()
the default value of the control on your form. If you want it to update for
every record, both new and existing, then put something like this in the
Current event of your form:

Me.MyDateField = Date()
 
Thanks for your support.

I have tried your suggestion and it does not seem to work. Please see my
syntax below and advise.

Private Sub txtDate_GotFocus()
txtDate = Format(Date, "dd/mm/yyyy")
End Sub

Thx
 
Alylia said:
Thanks for your support.

I have tried your suggestion and it does not seem to work. Please see my
syntax below and advise.

Private Sub txtDate_GotFocus()
txtDate = Format(Date, "dd/mm/yyyy")
End Sub

What doesn't work? Are you getting a error?

The syntax is correct. Make sure when look at the properties of the
txtDate textbox that the GotFocus event is pointing the event procedure.
Simply creating the event by cutting/pasting the text doesn't work --
it's gotta be linked.
 
I entered the syntax through the event procedure of txtDate. When txtDate get
the focus nothing happens, even when I try the double click procedure nothing
happens either.

Thanks for your continued support.
 
Back
Top