Command button to replace current record's field

  • Thread starter Thread starter Song
  • Start date Start date
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.
 
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.
 
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
 
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.
 
Back
Top