button command populates textbox

F

Fritz C

Greetings!
I would like to know how to make a button control on a click event put the
the current date and time (now()) into a textbox, which is a field from my
table. The trick seems to carefully elude me. I do appreciate all help on
this!
 
S

SteveM

In the event just put:
myTextBox = Now()

Substitute myTextBox with the name of your form field...

Steve
 
D

Don

It's pretty straight forward. On your form while in edit, you put a button
control on your form using your tool box. Simply drag a Command Button from
your toolbox and drop it anywhere on your form. You can name it AddDate or
something that you will know what it is later when reviewing your work. To
make this work, after you created a button, open the properties for the
button control and click the Event Tab then in the On Click field. Click the
field and then press the small box with the 3 little dots to open the Visual
Basic (VB) editing window. Below is a sample. Paste the following code in the
VB window. Some of the will already be in the window. Becareful to not
duplicate code. This code assumes that you named your button control AddDate.
You can rename your button control in properties by clicking the Other tab
then entering AddDate in the Name field

Private Sub AddDate_Click()
On Error GoTo Err_AddDate_Click


Screen.PreviousControl.SetFocus
Date = (Now())
Date.SetFocus

Exit_AddDate_Click:
Exit Sub

Err_AddDate_Click:
MsgBox Err.Description
Resume Exit_AddDate_Click

End Sub
 
Top