Command button to replace current record's field

S

Song

I have a continuous form with a command button in detailed band. On
click event, I want to replace 'checkin' field of current record with
=now(). Click the command button the 2nd time, replace same field with
blank. (toggle).

Thanks.
 
A

Allen Browne

To assign the current time to the checkin field, use this code:
Me.checkin = Now()
(or use the SetValue action in a macro if you prefer.)

It would be easier to use another button to blank the field. Code:
Me.checkin = Null

Otherwise you'll have to keep track of when the button was clicked first
(module level variable in the form's module), clear the variable (in
Form_Current when you move to a different record?), and test it in the Click
event of your button.
 
J

John W. Vinson

I have a continuous form with a command button in detailed band. On
click event, I want to replace 'checkin' field of current record with
=now(). Click the command button the 2nd time, replace same field with
blank. (toggle).

Thanks.

I'd expect you could use code like this in the button's click event, to put
Now into the field if it's NULL and Null into the field if it isn't:

Private Sub cmdMybutton_Click()
If IsNull(Me!checkin) Then
Me.Checkin = Now
Else
Me.Checkin = Null
End If
End Sub
 
J

jean felix

Song said:
I have a continuous form with a command button in detailed band. On
click event, I want to replace 'checkin' field of current record with
=now(). Click the command button the 2nd time, replace same field with
blank. (toggle).

Thanks.
 

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