Date Time Macro

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

Guest

In a form, I have a text box that I would like to populate with the date and
time by using a macro button.

TFTH,
Tom
 
This should do it: Assuming the name TextBox1 for your textbox and DateBtn
for your button, assign the following to your button's On Click event:

Private Sub DateBtn_Click()
TextBox1.Value = Now()
End Sub
 
K Dales,
Thanks for the information, however it did not completely solve the probelm.
When I click on the command button Access can not find the Macro Private Sub
DateBtn_Click(). Do I need to create a macro? If so what Action do I need
to assign?
TFTH,
Tom
 
K Dales,
Thanks for the information, however it did not completely solve the probelm.
When I click on the command button Access can not find the Macro Private Sub
DateBtn_Click(). Do I need to create a macro? If so what Action do I need
to assign?

PMFJI - What Dales suggested was NOT a macro and should not be typed
directly into the event. Instead, erase what's there, and click the
.... icon by the Click event. Choose Code Builder and type or copy and
paste the code into the VBA editor window (Access will give you the
SUB and END SUB lines for free). The event property should read

[Event Procedure]

when you're done.

John W. Vinson[MVP]
 
In a form, I have a text box that I would like to populate with the date and
time by using a macro button.

TFTH,
Tom

Are you aware that you can type Ctrl-: to do so already? No macro is
needed.

One solution would be to use a macro or some VBA code in the textbox's
DoubleClick event. I prefer VBA; you'ld click the ... icon, invoke the
Code Builder, and enter

Private Sub txtMyTextbox_DoubleClick()
Me!txtMyTextbox = Now
End Sub

For a Macro you'ld use the SetValue operation, again using Now as the
value.

John W. Vinson[MVP]
 
Back
Top